e6536fb459
* Python: Align AG-UI run continuity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aadad05d-2646-405f-8c62-a7a223abfc92 * Python: Refine AG-UI continuation ownership Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aadad05d-2646-405f-8c62-a7a223abfc92 * Python: Persist AG-UI checkpoint ownership Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aadad05d-2646-405f-8c62-a7a223abfc92 --------- Copilot-Session: aadad05d-2646-405f-8c62-a7a223abfc92
4.2 KiB
4.2 KiB
AG-UI Package (agent-framework-ag-ui)
AG-UI protocol integration for building agent UIs with the AG-UI standard.
Main Classes
AgentFrameworkAgent- Wraps agents for AG-UI compatibilityAgentFrameworkWorkflow- Wraps nativeWorkflowobjects, or acceptsworkflow_factory(thread_id)for thread-scoped workflow instances without subclassingAGUIChatClient- Chat client that speaks AG-UI protocolAGUIHttpService- HTTP service for AG-UI endpointsAGUIEventConverter- Converts between Agent Framework and AG-UI eventsadd_agent_framework_fastapi_endpoint()- Add AG-UI endpoint to FastAPI app (SupportsAgentRunorWorkflow)InMemoryAGUIThreadSnapshotStore- Memory-only latest AG-UI Thread Snapshot store for local development, demos, and tests
Types
AGUIRequest/AGUIChatOptions- Request typesAGUIThreadSnapshot/AGUIThreadSnapshotStore- Thread snapshot model with client-replayable data, private Session Continuation State, and a scoped async store protocolavailableInterrupts/resume- Optional canonical AG-UIInterruptandResumeEntryprotocol dataAgentState/RunMetadata- State management typesPredictStateConfig- Configuration for state prediction
Protocol Notes
- Outbound custom events are emitted as AG-UI
CUSTOM. - Usage metadata from
Content(type="usage")is surfaced asCUSTOMevents withname="usage". - Inbound custom event aliases are accepted:
CUSTOM,CUSTOM_EVENT, andcustom_event. - Multimodal user inputs support both legacy (
text,binary) and draft-style (image,audio,video,document) shapes. - Interrupted runs complete with
RUN_FINISHED.outcome.type == "interrupt"and canonicaloutcome.interrupts; do not document or add new flows that depend on the legacy top-levelRUN_FINISHED.interruptfield. InterruptandResumeEntrycome from theag-ui-protocolpackage (ag_ui.core), not from an Agent Framework-specific interrupt model.- Tool approval interrupts, including approvals surfaced through workflow
request_info, advertise standardapprovedand full-replacementeditedArgsresponses while retaining the existingacceptedalias and direct partial edits for MAF client compatibility. Acancelledresume completes normally without executing that call; resolved siblings in the same complete resume still proceed. - Approval-time execution preserves each call's complete result group. Follow-up user-input requests remain in the
resumed messages, while
TOOL_CALL_RESULTevents are emitted only for terminalfunction_resultcontents. - Approval responses for tools injected during
before_runare deferred to the in-run approval middleware rather than executed or rejected by the transport before those tools exist. _approval_lifecycle.pyis the sole owner of approval occurrence registration, trusted aliases, authority validation, claims, terminal outcomes, and retry deduplication. Runner code normalizes AG-UI protocol values and projects lifecycle outcomes but must not maintain a parallel pending-approval registry.- Default stateless conversation history is client-controlled, including historical tool calls and results. Never document conversational tool results as authorization or policy evidence; use deterministic server-side checks, server-validated approvals, or scoped authoritative snapshots.
confirm_changessnapshot cleanup resolves the synthetic confirmation back to its originalfunction_call_id; it must never concatenate unrelated tool results or record accepted changes without a matching real result.- SSE keepalive is endpoint-owned transport behavior configured through
add_agent_framework_fastapi_endpoint(keepalive_seconds=...). It emits SSE comments only; do not addPING,HEARTBEAT, orKEEPALIVEAG-UI events, and do not add runner-level keepalive settings.
Usage
from agent_framework.ag_ui import add_agent_framework_fastapi_endpoint
from fastapi import FastAPI
app = FastAPI()
add_agent_framework_fastapi_endpoint(app, agent)
Import Path
from agent_framework.ag_ui import AGUIChatClient, add_agent_framework_fastapi_endpoint
# or directly:
from agent_framework_ag_ui import AGUIChatClient