How to Fix 'callback not firing during development' in AutoGen (TypeScript)

By Cyprian AaronsUpdated 2026-04-21
callback-not-firing-during-developmentautogentypescript

If your AutoGen TypeScript callback is not firing during development, it usually means the event loop never reaches the code path you think it does, or the agent is waiting on a handler that was never registered correctly. In practice, this shows up when you wire AssistantAgent, UserProxyAgent, or a custom tool callback and then see nothing happen after run(), onMessage(), or a tool invocation.

The common symptom is not always a hard crash. More often you get silent failure, or an error like:

  • UnhandledPromiseRejection: callback not fired
  • Tool execution failed
  • No handler found for event
  • AssistantAgent did not receive response

The Most Common Cause

The #1 cause is passing an async callback in the wrong shape, or forgetting to return/await the promise AutoGen expects.

In TypeScript, this usually happens when you define a function correctly but register it incorrectly, especially with registerReply, tool handlers, or event listeners.

Broken vs fixed pattern

BrokenFixed
Callback is defined but never awaitedCallback is async and explicitly awaited
Handler returns nothingHandler returns the expected message/result
Wrong method signatureCorrect AutoGen signature
import { AssistantAgent, UserProxyAgent } from "autogen";

const assistant = new AssistantAgent({
  name: "assistant",
  llmConfig: { model: "gpt-4o-mini" },
});

const user = new UserProxyAgent({
  name: "user",
});

// ❌ Broken: callback registered incorrectly
assistant.registerReply(async (msg) => {
  console.log("Got message:", msg);
  // missing return
});

await user.initiateChat(assistant, "Hello");
import { AssistantAgent, UserProxyAgent } from "autogen";

const assistant = new AssistantAgent({
  name: "assistant",
  llmConfig: { model: "gpt-4o-mini" },
});

const user = new UserProxyAgent({
  name: "user",
});

// ✅ Fixed: return a reply in the expected format
assistant.registerReply(async (msg) => {
  console.log("Got message:", msg);

  return {
    role: "assistant",
    content: "Received your message.",
  };
});

await user.initiateChat(assistant, "Hello");

With AutoGen, the runtime often expects a concrete response object. If your callback resolves to undefined, the framework may keep waiting and your “callback not firing” issue is really “callback fired but produced no usable output.”

Other Possible Causes

1. You registered the callback on the wrong agent

This happens when the tool or reply handler is attached to UserProxyAgent but the event is happening on AssistantAgent, or vice versa.

// ❌ Wrong agent
user.registerReply(async () => ({ role: "user", content: "ok" }));
// ✅ Right agent
assistant.registerReply(async () => ({
  role: "assistant",
  content: "ok",
}));

2. Your callback signature does not match what AutoGen calls

Some handlers receive (message, context) or (toolArgs). If you assume one shape and AutoGen passes another, your logic can fail before it logs anything useful.

// ❌ Treating args like a string when it's an object
assistant.registerReply(async (msg) => {
  console.log(msg.toUpperCase());
});
// ✅ Inspect the actual payload first
assistant.registerReply(async (msg) => {
  console.log("payload:", JSON.stringify(msg, null, 2));
  return { role: "assistant", content: "ok" };
});

3. You forgot to await the top-level chat call

If your dev script exits early, callbacks never get a chance to run.

// ❌ Fire-and-forget in a short-lived process
user.initiateChat(assistant, "Ping");
console.log("done");
// ✅ Keep the process alive until completion
await user.initiateChat(assistant, "Ping");
console.log("done");

4. Tool registration mismatch in development

If you are using tools with AssistantAgent, make sure the tool name matches exactly and that it is registered before chat starts.

const tools = [{
  name: "lookupPolicy",
  description: "Fetch policy details",
  parameters: { type: "object", properties: {} },
}];

// ❌ Tool exists in schema but no implementation wired up
const assistant = new AssistantAgent({ name: "assistant", llmConfig });
// ✅ Tool schema + implementation both present
const assistant = new AssistantAgent({
  name: "assistant",
  llmConfig,
  tools,
});

How to Debug It

  1. Log entry and exit points

    • Put logs at the start of every callback.
    • Put logs right before every return.
    • If you see entry but not exit, your code is throwing or hanging.
  2. Check whether the handler is actually registered

    • Verify registration happens before initiateChat().
    • Confirm you are attaching to the correct instance of AssistantAgent or UserProxyAgent.
  3. Inspect promise handling

    • Every async callback should either return a value or throw intentionally.
    • Wrap suspicious code in try/catch and log the real exception.
  4. Reduce to one callback

    • Remove tools, memory, nested agents, and extra middleware.
    • Reproduce with one agent pair and one handler.
    • If it works in isolation, add pieces back one by one.

A good debugging pattern looks like this:

assistant.registerReply(async (msg) => {
  console.log("callback entered");

  try {
    const result = await doWork(msg);
    console.log("callback exiting");
    return { role: "assistant", content: result };
  } catch (err) {
    console.error("callback failed:", err);
    throw err;
  }
});

Prevention

  • Always return explicit values from AutoGen callbacks; don’t rely on side effects.
  • Register handlers before starting chat flows.
  • Add a small integration test that asserts your callback fires once per message.
  • In development scripts, always await agent runs so Node doesn’t exit early.

If you keep seeing this error after fixing the callback shape, assume it’s either registration order or an unhandled promise inside the handler. In AutoGen TypeScript projects, those two account for most “callback not firing” reports I see in real builds.


Keep learning

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

Related Guides