CopilotKit

Interactive components

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


"""MS Agent Framework 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. The MS Agent Framework does NOT have that primitive, so weadapt by delegating the time-picker interaction to a **frontend tool** that theagent calls by name (`schedule_meeting`). The frontend registers the tool via`useFrontendTool` with an async handler; that handler renders the interactivepicker, waits for the user to choose a slot (or cancel), and resolves the toolcall with the result. The backend only defines the system prompt and advertisesno local `schedule_meeting` implementation — the agent's tool call is satisfiedentirely by the frontend.See `src/agents/agent.py` for the related `approval_mode="always_require"`pattern used elsewhere in this package."""from __future__ import annotationsfrom textwrap import dedentfrom agent_framework import Agent, BaseChatClientfrom agent_framework_ag_ui import AgentFrameworkAgentSYSTEM_PROMPT = dedent(    """    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.    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.    Keep responses short and friendly. After you finish executing tools,    always send a brief final assistant message summarizing what happened so    the message persists.    """.strip())def create_interrupt_agent(chat_client: BaseChatClient) -> AgentFrameworkAgent:    """Instantiate the scheduling-only agent used by the interrupt-adapted demos."""    base_agent = Agent(        client=chat_client,        name="scheduling_agent",        instructions=SYSTEM_PROMPT,        # 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.        tools=[],    )    return AgentFrameworkAgent(        agent=base_agent,        name="CopilotKitMicrosoftAgentFrameworkInterruptAgent",        description=(            "Scheduling assistant for the interrupt-adapted demos. Delegates "            "the time-picker interaction to a frontend tool."        ),        require_confirmation=False,    )

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#

This framework implements the same interactive pause shape with a Promise-based frontend tool. The agent calls schedule_meeting, the client renders the picker, and the tool result resolves only after the user chooses a slot or cancels.

interrupt_agent.py
SYSTEM_PROMPT = dedent(    """    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.    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.    Keep responses short and friendly. After you finish executing tools,    always send a brief final assistant message summarizing what happened so    the message persists.    """.strip())def create_interrupt_agent(chat_client: BaseChatClient) -> AgentFrameworkAgent:    """Instantiate the scheduling-only agent used by the interrupt-adapted demos."""    base_agent = Agent(        client=chat_client,        name="scheduling_agent",        instructions=SYSTEM_PROMPT,        # 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.        tools=[],    )    return AgentFrameworkAgent(        agent=base_agent,        name="CopilotKitMicrosoftAgentFrameworkInterruptAgent",        description=(            "Scheduling assistant for the interrupt-adapted demos. Delegates "            "the time-picker interaction to a frontend tool."        ),        require_confirmation=False,    )