How to Fix 'callback not firing' in AutoGen (TypeScript)
Opening
If you’re seeing callback not firing in AutoGen TypeScript, it usually means the agent ran, but your event handler never got invoked. In practice, this shows up when you expect onMessage, onToolCall, or a custom callback to fire, but the control flow never reaches it.
Most of the time, this is not an AutoGen bug. It’s usually a mismatch between the agent API you’re using, how the callback is registered, or an async function that never gets awaited.
The Most Common Cause
The #1 cause is passing a callback in the wrong place or using the wrong method for the agent class you instantiated.
With AutoGen TypeScript, people often wire callbacks as if every agent exposes the same hook. That works poorly when you mix up AssistantAgent, UserProxyAgent, or a runtime/event-based API.
Broken vs fixed
| Broken pattern | Fixed pattern |
|---|---|
| Callback passed to the constructor where AutoGen doesn’t consume it | Register the callback on the actual event-producing method |
await missing on async run call | await the run so handlers can execute before process exit |
// BROKEN
import { AssistantAgent } from "@autogen/agent";
const agent = new AssistantAgent({
name: "support-agent",
model: "gpt-4o-mini",
// This callback is ignored by this API shape
onMessage: (msg) => {
console.log("Message:", msg);
},
});
agent.run("Hello"); // not awaited
// FIXED
import { AssistantAgent } from "@autogen/agent";
const agent = new AssistantAgent({
name: "support-agent",
model: "gpt-4o-mini",
});
agent.on("message", (msg) => {
console.log("Message:", msg);
});
await agent.run("Hello");
The important detail: if your process exits before the promise resolves, no callback fires. In Node.js, that looks like “nothing happened,” but the real issue is that execution ended early.
Other Possible Causes
1) You registered the handler on the wrong object
This happens when you attach a listener to a wrapper instead of the actual agent instance.
// Wrong
runtime.on("message", handler);
// Right
agent.on("message", handler);
If you are using a group chat or orchestrator object, confirm which object emits the event. GroupChatManager and AssistantAgent do not expose identical event surfaces.
2) The callback signature does not match what AutoGen emits
A handler can be present and still never run if TypeScript compiles but runtime data shape is wrong.
// Wrong: expecting a string, but AutoGen emits an object
agent.on("message", (text: string) => {
console.log(text.toUpperCase());
});
// Right
agent.on("message", (event: { content: string }) => {
console.log(event.content.toUpperCase());
});
If your code silently fails inside the handler, it can look like “callback not firing,” when in reality it fired and threw immediately.
3) You forgot to await an async tool or reply path
A common pattern in AutoGen agents is tool execution through async functions. If your tool returns a promise and you don’t await it properly, downstream callbacks may never execute in time.
// Broken
agent.registerTool("lookupPolicy", async () => {
fetchPolicy(); // missing await
});
// Fixed
agent.registerTool("lookupPolicy", async () => {
return await fetchPolicy();
});
Also check whether your top-level script exits too early:
// Broken
agent.run("Start workflow");
// Fixed
await agent.run("Start workflow");
4) Streaming/event mode is disabled
Some callbacks only fire when streaming or event emission is enabled in your configuration.
const agent = new AssistantAgent({
name: "claims-agent",
model: "gpt-4o-mini",
// If your setup supports streaming/event hooks, make sure it's enabled
stream: true,
});
If you are expecting token-level or intermediate events, verify that you’re not running in a non-streaming mode where only final output is returned.
How to Debug It
- •
Confirm whether the callback exists at runtime
- •Add a log immediately after registration.
- •If you use
.on(...), verify there’s no conditional path skipping registration.
- •
Check whether
run()or equivalent is awaited- •Look for:
agent.run(prompt); - •Replace with:
await agent.run(prompt);
- •Look for:
- •
Wrap the handler in a try/catch
- •A thrown error inside the callback can make it look like it never fired.
agent.on("message", (event) => { try { console.log(event.content); } catch (err) { console.error("handler failed", err); } }); - •
Print emitted events at the lowest level
- •If AutoGen exposes raw events, log them before any transformation.
- •This tells you whether the problem is emission or your handler logic.
Prevention
- •Register callbacks on the exact instance that emits them.
- •Always
awaitagent runs, tool calls, and orchestration steps. - •Keep handler signatures aligned with AutoGen’s actual event payloads; don’t guess shapes from memory.
- •Add one integration test that asserts your callback fires during a real run, not just unit tests around helper functions.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit