CopilotKit

Interactive components

Create approval flows where the agent pauses and waits for human input.


"""AG2 scheduling agent -- interrupt-adapted.This agent powers two demos (gen-ui-interrupt, interrupt-headless) that in theLangGraph showcase rely on the native `interrupt()` primitive withcheckpoint/resume. AG2 does NOT have that primitive, so we adapt using thesame "Strategy B" pattern as the MS Agent Framework port: the backend agent'ssystem prompt tells the LLM to call `schedule_meeting`, but no localimplementation is registered -- the tool is provided entirely by the frontendvia `useFrontendTool` with an async handler that returns a Promise resolvingonly once the user picks a time slot (or cancels).See `src/agents/agent.py` for the shared ConversableAgent used by most otherAG2 demos."""from __future__ import annotationsfrom autogen import ConversableAgent, LLMConfigfrom autogen.ag_ui import AGUIStreamfrom fastapi import FastAPISYSTEM_PROMPT = (    "You are a scheduling assistant. Whenever the user asks you to book a call "    "or schedule a meeting, you MUST call the `schedule_meeting` tool. Pass a "    "short `topic` describing the purpose of the meeting and, if known, an "    "`attendee` describing who the meeting is with.\n\n"    "The `schedule_meeting` tool is implemented on the client: it surfaces a "    "time-picker UI to the user and returns the user's selection. After the "    "tool returns, briefly confirm whether the meeting was scheduled and at "    "what time, or note that the user cancelled. Do NOT ask for approval "    "yourself -- always call the tool and let the picker handle the decision.\n\n"    "Keep responses short and friendly. After you finish executing tools, "    "always send a brief final assistant message summarizing what happened so "    "the message persists.")interrupt_agent = ConversableAgent(    name="scheduling_agent",    system_message=SYSTEM_PROMPT,    llm_config=LLMConfig({"model": "gpt-4o-mini", "stream": True}),    human_input_mode="NEVER",    max_consecutive_auto_reply=5,    # No backend tools. `schedule_meeting` is registered on the frontend    # via `useFrontendTool` and dispatched through the CopilotKit runtime.    # When the agent calls `schedule_meeting`, the request is routed to    # the frontend handler, which returns a Promise that only resolves    # once the user picks a slot -- equivalent to `interrupt()` in the    # LangGraph reference.    functions=[],)# AG-UI stream wrapperinterrupt_stream = AGUIStream(interrupt_agent)# FastAPI sub-app so agent_server.py can mount at /interrupt-adaptedinterrupt_app = FastAPI(title="AG2 Interrupt Agent")interrupt_app.mount("/", interrupt_stream.build_asgi())

What is this?#

Interactive generative UI creates flows where the agent pauses execution and waits for user input before continuing. This enables approval workflows, confirmation dialogs, and any scenario where human judgment is needed mid-execution.

When should I use this?#

Use interactive generative UI when you need:

  • Approval/rejection flows (e.g. "Run this command?")
  • User decisions that the agent should know about
  • Confirmation dialogs with structured responses
  • Any flow where the agent pauses for human judgment

How it works in code#

Not available on this framework. Interactive generative UI requires either a native interrupt primitive or a Promise-resolving frontend tool. For tool-call-based approval flows, use Human-in-the-loop instead.