Agent API#
Public classes and protocols for declaring agents, controllers, skills, and model execution.
PromptController#
PromptMessage#
SkillController#
Agent#
- class litestar_mcp.agent.Agent[source]#
Bases:
objectAgent definition with instructions, tools, skills, and an optional model binding.
- __post_init__()[source]#
Instantiate skill classes once, normalize tools, and reject duplicate tool names.
- Return type:
- property skill_instances: tuple[SkillController, ...]#
Return the instantiated skill controllers attached to this agent.
- property combined_instructions: str#
Return agent instructions joined with skill instructions by blank lines.
- __init__(name, description='', instructions='', tools=(), skills=(), model=None)#
AgentGroup#
- class litestar_mcp.agent.AgentGroup[source]#
Bases:
objectCoordinator and specialist agents with a group-owned transfer_to_agent tool.
AgentRuntime#
- class litestar_mcp.agent.AgentRuntime[source]#
Bases:
objectRuns agent turns with budgets, owner-scoped sessions, and streamed frames.
- __init__(target, *, default_model=None, budget=None, sessions=None, span_manager=None, compaction_hook=None, stream_buffer=64)[source]#
Initialize runtime with target agent or group and execution policies.
- async get_history(context, session_id)[source]#
Return conversation history scoped to connection owner.
- async produce(turn, send)[source]#
Execute turn loop as a producer coroutine emitting frames to the send stream.
- Return type:
TurnResponse
- open_stream(turn)[source]#
Open a background task group streaming frames to an in-memory receive stream.
- Return type:
GoogleGenAIClient#
- class litestar_mcp.agent.GoogleGenAIClient[source]#
Bases:
objectFirst-party Google GenAI model client wrapping google.genai with httpx2 support.
- __init__(model='gemini-3.8-flash', *, api_key=None, vertexai=None, project=None, location=None, thinking_budget=None, thinking_level=None, include_thoughts=None, temperature=None, http_client=None, http_options=None, client=None)[source]#
Initialize Google GenAI client with configuration.
MockModelClient#
ModelDelta#
- class litestar_mcp.agent.ModelDelta[source]#
Bases:
objectIncremental chunk emitted by a ModelClient during an agent turn.
- __init__(event_type, text=None, thought=None, tool_name=None, call_id=None, arguments=None, prompt_tokens=None, completion_tokens=None, provider_metadata=<factory>, thought_tokens=None)#
Tool#
ToolContext#
AgentChatController#
- class litestar_mcp.agent.AgentChatController[source]#
Bases:
ControllerSSE chat, synchronous turns, and owner-scoped history over an injected AgentRuntime.
- path: str#
A path fragment for the controller.
All route handlers under the controller will have the fragment appended to them. If not set it defaults to
/.
- after_request: AfterRequestHookHandler | None#
A sync or async function executed before a
Requestis passed to any route handler.If this function returns a value, the request will not reach the route handler, and instead this value will be used.
- after_response: AfterResponseHookHandler | None#
A sync or async function called after the response has been awaited.
It receives the
Requestinstance and should not return any values.
- before_request: BeforeRequestHookHandler | None#
A sync or async function called immediately before calling the route handler.
It receives the
Requestinstance and any non-Nonereturn value is used for the response, bypassing the route handler.
- cache_control: CacheControlHeader | None#
A
CacheControlHeaderheader to add to route handlers of this controller.Can be overridden by route handlers.
- dependencies: Dependencies | None#
A string keyed dictionary of dependency
Providerinstances.
- dto: type[AbstractDTO] | None | EmptyType#
AbstractDTOto use for (de)serializing and validation of request data.
- etag: ETag | None#
An
etagheader of typeETagto add to route handlers of this controller.Can be overridden by route handlers.
- exception_handlers: ExceptionHandlersMap | None#
A map of handler functions to status codes and/or exception types.
- guards: Sequence[Guard] | None#
A sequence of
Guardcallables.
- include_in_schema: bool | EmptyType#
A boolean flag dictating whether the route handler should be documented in the OpenAPI schema
- middleware: Sequence[Middleware] | None#
A sequence of
Middleware.
- opt: Mapping[str, Any] | None#
A string key mapping of arbitrary values that can be accessed in
Guardsor wherever you have access toRequestorASGI Scope.
- owner: Router#
The
RouterorLitestarapp that owns the controller.This value is set internally by Litestar and it should not be set when subclassing the controller.
- parameters: ParametersMap | None#
A mapping of
Parameterdefinitions available to all application paths.
- request_class: type[Request] | None#
A custom subclass of
Requestto be used as the default request for all route handlers under the controller.
- request_max_body_size: int | None | EmptyType#
Maximum allowed size of the request body in bytes. If this size is exceeded, a '413 - Request Entity Too Large' error response is returned.
- response_class: type[Response] | None#
A custom subclass of
Responseto be used as the default response for all route handlers under the controller.
- response_cookies: ResponseCookies | None#
A list of
Cookieinstances.
- response_headers: ResponseHeaders | None#
A string keyed dictionary mapping
ResponseHeaderinstances.
- return_dto: type[AbstractDTO] | None | EmptyType#
AbstractDTOto use for serializing outbound response data.
- security: Sequence[SecurityRequirement] | None#
A sequence of dictionaries that to the schema of all route handlers under the controller.
- signature_namespace: dict[str, Any]#
A mapping of names to types for use in forward reference resolution during signature modelling.
- signature_types: Sequence[Any]#
A sequence of types for use in forward reference resolution during signature modelling.
These types will be added to the signature namespace using their
__name__attribute.
- tags: Sequence[str] | None#
A sequence of string tags that will be appended to the schema of all route handlers under the controller.
- type_decoders: TypeDecodersSequence | None#
A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.
- type_encoders: TypeEncodersMap | None#
A mapping of types to callables that transform them into types supported for serialization.
- websocket_class: type[WebSocket] | None#
A custom subclass of
WebSocketto be used as the default websocket for all route handlers under the controller.
AgentStreamFrame#
- class litestar_mcp.agent.AgentStreamFrame[source]#
Bases:
StructTyped SSE frame emitted during agent execution.
- to_sse_message(type_encoders=None)[source]#
Encode as an SSE message whose id is seq when non-zero and whose event is event_type.
iter_agent_stream#
MCPHttpClient#
TurnBudget#
BudgetExceededError#
SpanManager#
- class litestar_mcp.core.observability.SpanManager[source]#
Bases:
objectLazy OpenTelemetry span manager with graceful degradation.
Provides zero-overhead no-op execution when OpenTelemetry is not installed or when spans are disabled.
- __init__(telemetry=None)[source]#
Initialize the SpanManager with configuration and resolve trace API if enabled.
- start_agent_span(agent_name='', action='invoke_agent', *, agent_group=None, session_id=None, turn_id=None, model=None, provider=None, attributes=None)[source]#
Start a span representing an agent turn with standard GenAI semantic conventions.
- Return type:
- start_tool_span(tool_name='', call_id=None, *, attributes=None)[source]#
Start a span representing a single tool execution.
- Return type:
- set_usage(span, prompt_tokens, completion_tokens)[source]#
Record input and output token usage on an agent turn span.
- Return type:
- start_span(name, attributes=None)[source]#
Start a generic span with custom attributes.
- Return type: