SubAgent is a Pydantic model. Set any field below as a keyword argument when you construct it.
SubAgent is a context manager and can be used in a with statement.
Fields
Methods
start_llm
_current_llm contextvar so the LLM is visible via
get_current_llm() regardless of whether a context manager is used.
Pins the LLM’s OTel parent to this SubAgent’s span when the SubAgent
has been entered.
start_tool
start_subagent
record
system_instructions, agent_id,
…) into a single keyword call. Only fields explicitly passed
(non-None) are applied; existing values are preserved. Returns
self for chaining. Mirrors Turn.record / LLM.record.
Note: on the streaming (with) path the sub-agent span is named
from name at __enter__, so set name via start_subagent
/ turn.subagent rather than record if you need the span name
to reflect it; record still updates the gen_ai.agent.name
attribute.
end
start
__enter__ without the with.
Pass set_current=False to start_subagent when sub-agents can be in flight
concurrently. end() detaches via ContextVar.reset, which
silently corrupts the ambient context stack when overlapping spans
end out of LIFO order; the surviving sibling stops being current,
and the last detach restores an already-ended span. Children created
through start_llm / start_tool / start_subagent nest under
this span either way, because those factories thread an explicit
parent context.
record_error
end() when ready.
set_attributes
span.set_attributes({"weave.tag": "value"}). Mirrors OTel’s
Span.set_attributes.
Must be called after a start_* factory, start(), or with
starts the span, and before it ends. Outside that window the call is a
no-op and logs a warning. For batch ingest, populate the object’s declared fields
directly and pass it to log_turn / log_conversation.