Prompt

I'm building an agent that calls tools, how do I record all the intermediate steps?

Technology / Observability1 observationLast seen Oct 9, 2026

Latest observation

Oct 9, 2026OpenAI APIWeb search: off

To record all intermediate steps in a tool-calling agent, the usual pattern is:

  1. Log every model action

    • Prompt sent to the model
    • Model output
    • Any tool call name + arguments
  2. Log every tool execution

    • Tool name
    • Inputs
    • Outputs
    • Errors / retries
    • Timestamps / latency
  3. Store the full trace as a sequence of events A simple structure is:

[
  {"type": "llm_request", "prompt": "..."},
  {"type": "llm_response", "content": "...", "tool_call": {"name": "search", "args": {"q": "weather"}}},
  {"type": "tool_request", "name": "search", "args": {"q": "weather"}},
  {"type": "tool_response", "name": "search", "result": "..."},
  {"type": "llm_response", "content": "It is sunny."}
]
  1. If you’re using an agent framework, enable tracing/callbacks Most frameworks expose hooks like:

    • on_llm_start, on_llm_end
    • on_tool_start, on_tool_end
    • on_chain_start, on_chain_end
  2. Keep a run/session ID This lets you connect all intermediate steps from one agent invocation.

  3. Persist to a datastore or observability system Common options:

    • SQLite/Postgres for simple persistence
    • JSONL files for easy debugging
    • OpenTelemetry / tracing backends for production
    • Framework-specific tracing tools if available

Example pseudo-code:

trace = []

def log(event):
    trace.append({**event, "ts": time.time()})

log({"type": "llm_request", "messages": messages})
resp = llm(messages)
log({"type": "llm_response", "output": resp})

if resp.tool_call:
    log({"type": "tool_request", "tool": resp.tool_call.name, "args": resp.tool_call.args})
    tool_result = tools[resp.tool_call.name](**resp.tool_call.args)
    log({"type": "tool_response", "result": tool_result})

If you want, I can also show:

  • how to do this in LangChain
  • how to do this in OpenAI tool calling
  • or a framework-agnostic event schema for agent traces

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.