Skip to main content
The Trajectory extension allows you to visualize the step-by-step reasoning process of your agent as it runs. Trajectory steps appear as expandable sections in the UI, helping users understand your agent’s thought process, making the interaction more transparent and trustworthy.

Example: Basic Usage

1

Import the trajectory extension

Import TrajectoryExtensionServer and TrajectoryExtensionSpec from agentstack_sdk.a2a.extensions.
2

Inject the extension

Add a trajectory parameter to your agent function using the Annotated type hint with TrajectoryExtensionSpec().
3

Yield trajectory metadata

Call yield trajectory.trajectory_metadata() with a title and content to add a step to the trajectory.

Markdown Support

The content field of trajectory_metadata supports Markdown, which is rendered directly in the UI. Supported elements include:
  • Headers
  • Bold and italic text
  • Ordered and unordered lists
  • Tables
  • Code blocks
  • Links
  • Checklists

Grouping Trajectories

Use the group_id parameter to update trajectory content in the UI. Each update replaces the previous content (and title, if defined) for the same group_id:

Common Patterns

Progress Steps:
Decision Points:
Error Handling:
Multi-step Process with Live Updates:

Example: Advanced Usage

For a more advanced example, see trajectory_agent.py.