Skip to main content
The Trace Service in the Galtea SDK allows you to collect, manage, and persist traces that capture the internal operations of your AI agents during inference. This Service is exposed by the galtea.traces object.
Remember that we will be using the galtea object. More information here.

Two Approaches to Trace Collection

The SDK provides two ways to collect traces:

1. Automatic Collection with with generate()

When using galtea.inference_results.generate(), trace collection is handled automatically:
@trace(type=TraceType.TOOL)
def fetch_user_data(user_id: str) -> dict:
    return {"name": "John Doe", "email": "[email protected]"}


@trace(type=TraceType.GENERATION)
def generate_response(prompt: str) -> str:
    return "Generated response..."


class MyOverviewAgent(Agent):
    def call(self, input_data: AgentInput) -> AgentResponse:
        user = fetch_user_data("user_123")
        response = generate_response("Hello")
        return AgentResponse(content=response)


# Use generate() for automatic trace context management
inference_result = galtea.inference_results.generate(
    agent=MyOverviewAgent(),
    session=session,
    user_input="Show me user data",
)

2. Manual Collection with Context Management

For full control over the trace lifecycle, use set_context() and clear_context(): Set context before running traced functions:
trace_context = set_context(inference_result_id=inference_result_id)
Then run your traced functions within this context set/open. Once done, clear the context to flush and detach:
clear_context(trace_context)
Use galtea.inference_results.generate() for automatic trace collection instead of manual collection.

Service Methods

Context Management

Direct API Methods

Trace

Understand how traces capture the internal operations of your AI agents.