Agent ABC + its neutral streamed-event vocabulary.
Re-exports the Agent interface (and its PresetSpec / SubAgentSpec
inputs and AgentInterruptedError error) alongside the StreamEvent types an
agent’s astream yields and run drains.
Agent
tai42_contract.agent.base.Agent
run; override
astream only when the agent produces real per-step events.
Subclasses declare three class attributes that drive auto-tool generation:
tool_name— the registered name (also the auto-generated tool name);tool_description— the LLM-facing description (carried, not lost);ToolInput— a JSON-able pydantic model of the tool params. Livetools=is deliberately NOT inToolInput(API-only viaastream); a non-JSON field fails loudly atmodel_json_schema()time.
spec_runnable is a capability marker (default False):
spec_runnable = True declares that this agent’s ToolInput advertises
EXACTLY the composable fields its runtime honors — no more, no less. This lets
a generic UI gate authoring controls on the input schema’s fields: it renders a
control only for an advertised (honored) field, and baking an un-advertised
field is rejected at author time. The declaration is the implementation’s — it
is never inferred, and no agent name is ever hardcoded. Because every
ToolInput field of a spec_runnable agent is honored, all of them are
preset-bakeable; preset_bakeable_fields covers the other case.
preset_bakeable_fields names the ToolInput fields whose baked
(preset fixed_kwargs) value the runtime honors on an agent that is NOT
UI-composable — declaring a field here implies no UI control at all, only that
a hidden baked value is passed through and acted on. A field is preset-bakeable
iff the agent is spec_runnable (all fields, above) OR the field is listed
here. Like spec_runnable it is the implementation’s own declaration, never
inferred; every listed name must be a real ToolInput field. The empty
default means nothing is bakeable unless the agent is spec_runnable.
Attributes
Members
from_tool_input
tai42_contract.agent.base.Agent.from_tool_input
ToolInput instance to run kwargs.
Passes through every set field with nested pydantic values (presets,
subagents, inline_skills) kept as model instances, since run
and the resolvers it calls read them by attribute. model_dump is
deliberately NOT used — it would flatten those nested models to dicts.
Agents whose JSON tool-face shape differs from their run signature
override this.
Any error an override raises must be a constant, hand-authored message and
must NOT interpolate input values: the agent run routes surface these
messages verbatim to the caller, and the baked input can carry credentials
the caller is not entitled to see.
Parameters
run
tai42_contract.agent.base.Agent.run
tools/tool_names/presets) are uniform only for
tools-agent-shaped agents; role-specific agents (voting/vqa/refine/
mcp_tools) read their own params off **kwargs. response_format is
typed Any because the deep path passes a JSON-Schema dict while
the tools-agent path passes a pydantic class. resume_checkpoint_id
forks past an aborted turn, distinct from resume (the interrupt
answer).
Parameters
astream
tai42_contract.agent.base.Agent.astream
str becomes a
MessageFinal (plain-text answer), any other value a
StructuredFinal (the structured response_format object).
Streaming agents override this with the real per-step projection and
implement run by draining their own astream via
_drain.
Parameters
AgentInterruptedError
tai42_contract.agent.base.AgentInterruptedError
run/_drain when a non-streaming caller drains a run that
paused on an interrupt. A non-streaming caller cannot act on an interrupt, so
it surfaces loudly rather than returning a partial. interrupts is the list
of InterruptFinal events the run emitted.
Attributes
InterruptFinal
tai42_contract.agent.events.InterruptFinal
interrupt_id is the graph interrupt id (echoed back when resuming);
payload is the interrupt value the agent raised (e.g. the option set);
reason is an optional human-facing label. This event is emitted verbatim
as one SSE frame (type: "interrupt_final"); a consumer reads
interrupt_id, payload and reason off it — do NOT rename payload
or drop reason.
Attributes
MessageDelta
tai42_contract.agent.events.MessageDelta
MessageFinal
tai42_contract.agent.events.MessageFinal
PresetSpec
tai42_contract.agent.base.PresetSpec
StructuredTool at
run time (see resolve_tools). A sub-flow is base_tool="flow" with
fixed_kwargs={"flow_graph": ...}.
Attributes
ReasoningStep
tai42_contract.agent.events.ReasoningStep
RunUsage
tai42_contract.agent.events.RunUsage
None.
Attributes
StreamEvent
tai42_contract.agent.events.StreamEvent
Agent streams. type is a stable
discriminator; final marks a terminal event (see the terminal rule in
Agent._drain).
Attributes
StructuredFinal
tai42_contract.agent.events.StructuredFinal
data is the object the
agent produced — typically the validated response_format instance. A
plain-text answer is carried by MessageFinal instead. Terminal.
Attributes
SubAgentSpec
tai42_contract.agent.base.SubAgentSpec
inline_skills items are plain dicts
({"name", "content"}). JSON callers use the richer DeepSubAgentSpec
(full field set) instead of this type.
tools is list[Any] in the contract (live StructuredTool objects in
the impl) — a vendor type cannot be a runtime pydantic field here.
Attributes
ToolCallStep
tai42_contract.agent.events.ToolCallStep
call_id is the
model-assigned id the matching ToolResultStep carries.
Attributes
ToolResultStep
tai42_contract.agent.events.ToolResultStep
ToolCallStep by
call_id. result is passed through untouched.
Attributes

