Tracing#

This page presents all APIs and classes related to tracing in PyAgentSpec.

Trace#

class pyagentspec.tracing.trace.Trace(name=None, id=None, span_processors=None, shutdown_on_exit=True, root_span=None)#

Bases: object

The root of a collection of Spans.

It is used to group together all the spans and events emitted during the execution of an assistant.

Parameters:
  • name (str | None) –

  • id (str | None) –

  • span_processors (List[SpanProcessor] | None) –

  • shutdown_on_exit (bool) –

  • root_span (Span | None) –

is_async_mode_active()#
Return type:

bool

SpanProcessor#

class pyagentspec.tracing.spanprocessor.SpanProcessor(mask_sensitive_information=True)#

Bases: ABC

Interface which allows hooks for Span start and end method invocations.

Aligned with OpenTelemetry APIs.

Parameters:

mask_sensitive_information (bool) –

abstract on_end(span)#

Called when a Span is ended.

Parameters:

span (Span) – The spans that ends

Return type:

None

abstract async on_end_async(span)#

Called when a Span is ended. Asynchronous method.

Parameters:

span (Span) – The spans that ends

Return type:

None

abstract on_event(event, span)#

Called when an Event is triggered.

Parameters:
  • event (Event) – The event that is happening

  • span (Span) – The spans where the event occurs

Return type:

None

abstract async on_event_async(event, span)#

Called when an Event is triggered. Asynchronous method.

Parameters:
  • event (Event) – The event that is happening

  • span (Span) – The spans where the event occurs

Return type:

None

abstract on_start(span)#

Called when a Span is started.

Parameters:

span (Span) – The spans that starts

Return type:

None

abstract async on_start_async(span)#

Called when a Span is started. Asynchronous method.

Parameters:

span (Span) – The spans that starts

Return type:

None

abstract shutdown()#

Called when a Trace is shutdown.

Return type:

None

abstract async shutdown_async()#

Called when a Trace is shutdown. Asynchronous method.

Return type:

None

abstract startup()#

Called when a Trace is started.

Return type:

None

abstract async startup_async()#

Called when a Trace is started. Asynchronous method.

Return type:

None

Spans#

class pyagentspec.tracing.spans.span.Span(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>)#

Bases: BaseModelWithSensitiveInfo

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

add_event(event)#

Add an event to the span and trigger on_event on the active SpanProcessors.

Parameters:

event (Event) –

Return type:

None

async add_event_async(event)#

Add an event to the span and trigger on_event_async on the active SpanProcessors.

Parameters:

event (Event) –

Return type:

None

description: str#

The description of the span.

end()#

End the span.

This includes calling the on_end method of the active SpanProcessors.

Return type:

None

async end_async()#

End the span. Asynchronous method.

This includes calling the on_end_async method of the active SpanProcessors.

Return type:

None

end_time: int | None#

The timestamp of when the span was closed

events: List[Event]#

The list of events recorded in the scope of this span

metadata: dict[str, Any]#

Metadata related to the span

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

start()#

Start the span.

This includes calling the on_start method of the active SpanProcessors.

Return type:

None

async start_async()#

Start the span. Asynchronous method.

This includes calling the on_start_async method of the active SpanProcessors.

Return type:

None

start_time: int | None#

The timestamp of when the span was started

class pyagentspec.tracing.spans.root.RootSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>)#

Bases: Span

Span that covers a whole Trace.

  • Starts when: a Trace is started

  • Ends when: a Trace is closed

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

description: str#

The description of the span.

end_time: int | None#

The timestamp of when the span was closed

events: List[Event]#

The list of events recorded in the scope of this span

metadata: dict[str, Any]#

Metadata related to the span

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

start_time: int | None#

The timestamp of when the span was started

class pyagentspec.tracing.spans.agent.AgentExecutionSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>, agent)#

Bases: Span

Span to represent the execution of an agent. Can be nested when executing sub-agents.

  • Starts when: agent execution starts

  • Ends when: the agent execution is completed, and the result is ready to be processed

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

  • agent (Agent) –

agent: Agent#

The Agent being executed

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

class pyagentspec.tracing.spans.flow.FlowExecutionSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>, flow)#

Bases: Span

Span that covers the execution of a Flow.

  • Starts when: the StartNode execution of this flow starts

  • Ends when: one of the EndNode execution finishes

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

  • flow (Flow) –

flow: Flow#

The Flow being executed

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

class pyagentspec.tracing.spans.node.NodeExecutionSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>, node)#

Bases: Span

Span that covers the execution of a Node.

  • Starts when: the node execution starts on the given inputs

  • Ends when: the node execution ends and outputs are ready to be processed

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

  • node (Node) –

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

node: Node#

The Node being executed

class pyagentspec.tracing.spans.tool.ToolExecutionSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>, tool)#

Bases: Span

Span that covers a tool execution. This does not include client tools.

  • Starts when: tool execution starts

  • Ends when: the tool execution is completed and the result is ready to be processed

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

  • tool (Tool) –

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

tool: Tool#

The Tool being executed

class pyagentspec.tracing.spans.llm.LlmGenerationSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>, llm_config)#

Bases: Span

Span that covers the whole LLM generation process

  • Starts when: the LLM generation request is received and the LLM call is performed

  • Ends when: the LLM output was generated, and it’s ready to be processed

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

  • llm_config (LlmConfig) –

llm_config: LlmConfig#

The LlmConfig that performs the generation

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

class pyagentspec.tracing.spans.managerworkers.ManagerWorkersExecutionSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>, managerworkers)#

Bases: Span

Span to represent the execution of a ManagerWorkers. Can be nested when executing sub-agents.

  • Starts when: manager-workers pattern execution starts

  • Ends when: the manager-workers execution is completed and the result is ready to be processed

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

  • managerworkers (ManagerWorkers) –

managerworkers: ManagerWorkers#

The ManagerWorkers being executed

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

class pyagentspec.tracing.spans.swarm.SwarmExecutionSpan(*, id=<factory>, name=None, description='', start_time=None, end_time=None, events=<factory>, metadata=<factory>, swarm)#

Bases: Span

Span to represent the execution of a Swarm. Can be nested when executing sub-agents.

  • Starts when: swarm pattern execution starts

  • Ends when: the swarm execution is completed and the result is ready to be processed

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • start_time (int | None) –

  • end_time (int | None) –

  • events (List[Event]) –

  • metadata (dict[str, Any]) –

  • swarm (Swarm) –

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Span__context)#

Set the default name if it is not provided.

Parameters:

_Span__context (Any) –

Return type:

None

swarm: Swarm#

The Swarm being executed

Events#

class pyagentspec.tracing.events.event.Event(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>)#

Bases: BaseModelWithSensitiveInfo

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

description: str#

The description of the event.

metadata: dict[str, Any]#

Metadata related to the event

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(_Event__context)#

Set the default name if it is not provided.

Parameters:

_Event__context (Any) –

Return type:

None

timestamp: int#

The timestamp of when the event occurred

Agent Events#

class pyagentspec.tracing.events.agent.AgentExecutionStart(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, agent, inputs)#

Bases: Event

The execution of an agent is starting. Emitted when an AgentExecutionSpan starts.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • agent (Agent) –

  • inputs (Dict[str, Any]) –

agent: Agent#

The Agent being executed

inputs: Dict[str, Any]#

The inputs used for the agent’s execution, one per property defined in agent’s inputs

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pyagentspec.tracing.events.agent.AgentExecutionEnd(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, agent, outputs)#

Bases: Event

The execution of an agent is ending. Emitted when an AgentExecutionSpan ends.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • agent (Agent) –

  • outputs (Dict[str, Any]) –

agent: Agent#

The Agent being executed

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

outputs: Dict[str, Any]#

The outputs generated by the agent’s execution, one per property defined in agent’s outputs

Flow Events#

class pyagentspec.tracing.events.flow.FlowExecutionStart(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, flow, inputs)#

Bases: Event

The execution of a flow is starting. Emitted when a FlowExecutionSpan starts.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • flow (Flow) –

  • inputs (Dict[str, Any]) –

flow: Flow#

The Flow being executed

inputs: Dict[str, Any]#

The inputs used for the flow’s execution, one per property defined in flow’s inputs

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pyagentspec.tracing.events.flow.FlowExecutionEnd(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, flow, outputs, branch_selected)#

Bases: Event

The execution of a flow is ending. Emitted at a FlowExecutionSpan ends.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • flow (Flow) –

  • outputs (Dict[str, Any]) –

  • branch_selected (str) –

branch_selected: str#

The exit branch selected at the end of the Flow’s execution

flow: Flow#

The Flow being executed

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

outputs: Dict[str, Any]#

The outputs generated by the flow’s execution, one per property defined in flow’s outputs

class pyagentspec.tracing.events.node.NodeExecutionStart(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, node, inputs)#

Bases: Event

The execution of a node is starting. Emitted ad a NodeExecutionSpan starts.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • node (Node) –

  • inputs (Dict[str, Any]) –

inputs: Dict[str, Any]#

The inputs used for the node’s execution, one per property defined in node’s inputs

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

node: Node#

The Node being executed

class pyagentspec.tracing.events.node.NodeExecutionEnd(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, node, outputs, branch_selected)#

Bases: Event

The execution of a node is ending. Emitted at a NodeExecutionSpan ends.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • node (Node) –

  • outputs (Dict[str, Any]) –

  • branch_selected (str) –

branch_selected: str#

The exit branch selected at the end of the Node’s execution

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

node: Node#

The Node being executed

outputs: Dict[str, Any]#

The outputs generated by the node’s execution, one per property defined in node’s outputs

Tool Events#

class pyagentspec.tracing.events.tool.ToolExecutionRequest(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, tool, inputs, request_id)#

Bases: Event

A tool execution request is received. Emitted when a ToolExecutionSpan starts, or a client tool is called.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • tool (Tool) –

  • inputs (Dict[str, Any]) –

  • request_id (str) –

inputs: Dict[str, Any]#

The input values that should be used to execute the tool, one per property defined in tool’s inputs

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

request_id: str#

Identifier of the tool execution request

tool: Tool#

The Tool being executed

class pyagentspec.tracing.events.tool.ToolExecutionResponse(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, tool, outputs, request_id)#

Bases: Event

A tool execution finishes and a result is received. Raised when a ToolExecutionSpan ends, or a client tool result is received.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • tool (Tool) –

  • outputs (Dict[str, Any]) –

  • request_id (str) –

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

outputs: Dict[str, Any]#

The return value generated by the tool’s execution, one per property defined in tool’s outputs

request_id: str#

Identifier of the tool execution request

tool: Tool#

The Tool being executed

class pyagentspec.tracing.events.tool.ToolConfirmationRequest(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, tool, request_id, tool_execution_request_id=None)#

Bases: Event

A tool confirmation request is raised.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • tool (Tool) –

  • request_id (str) –

  • tool_execution_request_id (str | None) –

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

request_id: str#

Identifier of the confirmation request

tool: Tool#

The Tool being executed

tool_execution_request_id: str | None#

Identifier of the tool execution request this confirmation relates to

class pyagentspec.tracing.events.tool.ToolConfirmationResponse(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, tool, execution_confirmed, request_id, tool_execution_request_id=None)#

Bases: Event

A tool confirmation response is received.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • tool (Tool) –

  • execution_confirmed (bool) –

  • request_id (str) –

  • tool_execution_request_id (str | None) –

execution_confirmed: bool#

Whether the execution of the tool was confirmed

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

request_id: str#

Identifier of the confirmation request

tool: Tool#

The Tool being executed

tool_execution_request_id: str | None#

Identifier of the tool execution request this confirmation relates to

LLM Events#

class pyagentspec.tracing.events.llmgeneration.ToolCall(*, call_id, tool_name, arguments)#

Bases: BaseModel

Model for an LLM tool call.

Parameters:
  • call_id (str) –

  • tool_name (str) –

  • arguments (str) –

arguments: str#

The values of the arguments that should be passed to the tool, in JSON format

call_id: str#

Identifier of the tool call

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

tool_name: str#

The name of the tool that should be called

class pyagentspec.tracing.messages.message.Message(*, id=None, content, sender=None, role)#

Bases: BaseModel

Model used to specify LLM message details in events and spans

Parameters:
  • id (str | None) –

  • content (str) –

  • sender (str | None) –

  • role (str) –

content: str#

Content of the message

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

role: str#

Role of the sender of the message. Typically ‘user’, ‘assistant’, or ‘system’

sender: str | None#

Sender of the message

class pyagentspec.tracing.events.llmgeneration.LlmGenerationRequest(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, llm_config, prompt, tools, request_id, llm_generation_config=None)#

Bases: Event

An LLM generation request was received. Start of the LlmGenerationSpan.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • llm_config (LlmConfig) –

  • prompt (List[Message]) –

  • tools (List[Tool]) –

  • request_id (str) –

  • llm_generation_config (LlmGenerationConfig | None) –

llm_config: LlmConfig#

The LlmConfig that performs the generation

llm_generation_config: LlmGenerationConfig | None#

The LLM configuration used for this LLM call

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

prompt: List[Message]#

The content of the prompt that will be sent to the LLM.

request_id: str#

Identifier of the generation request

tools: List[Tool]#

The list of tools sent as part of the generation request

class pyagentspec.tracing.events.llmgeneration.LlmGenerationChunkReceived(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, llm_config, content, request_id, tool_calls=[], completion_id=None, output_tokens=None)#

Bases: Event

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • llm_config (LlmConfig) –

  • content (str | None) –

  • request_id (str) –

  • tool_calls (List[ToolCall]) –

  • completion_id (str | None) –

  • output_tokens (int | None) –

completion_id: str | None#

The identifier of the completion related to this response chunk

content: str | None#

The content of the chunk received from the LLM

llm_config: LlmConfig#

The LlmConfig that performs the generation

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

output_tokens: int | None#

Number of output tokens for this chunk

request_id: str#

Identifier of the generation request

tool_calls: List[ToolCall]#

The list of tool calls that should be performed, received as part of the generation response chunk

class pyagentspec.tracing.events.llmgeneration.LlmGenerationResponse(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, llm_config, content, tool_calls=[], request_id, completion_id=None, input_tokens=None, output_tokens=None)#

Bases: Event

An LLM response was received. End of an LlmGenerationSpan.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • llm_config (LlmConfig) –

  • content (str | None) –

  • tool_calls (List[ToolCall]) –

  • request_id (str) –

  • completion_id (str | None) –

  • input_tokens (int | None) –

  • output_tokens (int | None) –

completion_id: str | None#

The identifier of the completion related to this response

content: str | None#

The content of the response received from the LLM

input_tokens: int | None#

Number of input tokens

llm_config: LlmConfig#

The LlmConfig that performed the generation

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

output_tokens: int | None#

Number of output tokens

request_id: str#

Identifier of the generation request

tool_calls: List[ToolCall]#

The list of tool calls that should be performed, received as part of the generation response

Multi-agent Events#

class pyagentspec.tracing.events.managerworkers.ManagerWorkersExecutionStart(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, managerworkers, inputs)#

Bases: Event

The execution of a manager-workers is starting. Emitted when a ManagerWorkersExecutionSpan starts

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • managerworkers (ManagerWorkers) –

  • inputs (Dict[str, Any]) –

inputs: Dict[str, Any]#

The inputs used for the manager-workers’s execution, one per property defined in manager-workers’s inputs

managerworkers: ManagerWorkers#

The ManagerWorkers being executed

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pyagentspec.tracing.events.managerworkers.ManagerWorkersExecutionEnd(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, managerworkers, outputs)#

Bases: Event

The execution of a manager-workers is ending. Emitted when a ManagerWorkersExecutionSpan ends.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • managerworkers (ManagerWorkers) –

  • outputs (Dict[str, Any]) –

managerworkers: ManagerWorkers#

The ManagerWorkers being executed

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

outputs: Dict[str, Any]#

The outputs generated by the manager-workers’s execution, one per property defined in manager-workers’s outputs

class pyagentspec.tracing.events.swarm.SwarmExecutionStart(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, swarm, inputs)#

Bases: Event

The execution of a swarm is starting. Emitted when a SwarmExecutionSpan starts

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • swarm (Swarm) –

  • inputs (Dict[str, Any]) –

inputs: Dict[str, Any]#

The inputs used for the swarm’s execution, one per property defined in swarm’s inputs

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

swarm: Swarm#

The Swarm being executed

class pyagentspec.tracing.events.swarm.SwarmExecutionEnd(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, swarm, outputs)#

Bases: Event

The execution of a swarm is ending. Emitted when a SwarmExecutionSpan ends.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • swarm (Swarm) –

  • outputs (Dict[str, Any]) –

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

outputs: Dict[str, Any]#

The outputs generated by the swarm’s execution, one per property defined in swarm’s outputs

swarm: Swarm#

The Swarm being executed

Other Events#

class pyagentspec.tracing.events.exception.ExceptionRaised(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, exception_type, exception_message, exception_stacktrace='')#

Bases: Event

This event is recorded whenever an exception occurs.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • exception_type (str) –

  • exception_message (str) –

  • exception_stacktrace (str) –

exception_message: str#

Message of the exception

exception_stacktrace: str#

Stacktrace of the exception

exception_type: str#

Type of the exception

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pyagentspec.tracing.events.humanintheloop.HumanInTheLoopRequest(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, request_id, content)#

Bases: Event

A human-in-the-loop (HITL) intervention is required. Emitted when the execution is interrupted due to HITL request

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • request_id (str) –

  • content (Dict[str, Any]) –

content: Dict[str, Any]#

The content of the request forwarded to the user

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

request_id: str#

Identifier of the human-in-the-loop request

class pyagentspec.tracing.events.humanintheloop.HumanInTheLoopResponse(*, id=<factory>, name=None, description='', timestamp=<factory>, metadata=<factory>, request_id, content)#

Bases: Event

A human-in-the-loop response is provided. Emitted when the execution restarts after HITL response.

Parameters:
  • id (str) –

  • name (str | None) –

  • description (str) –

  • timestamp (int) –

  • metadata (dict[str, Any]) –

  • request_id (str) –

  • content (Dict[str, Any]) –

content: Dict[str, Any]#

The content of the response received from the user

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

request_id: str#

Identifier of the human-in-the-loop request