Skip to main content

Trace AI agent execution — LLM calls, tool calls, costs and latency

Project description

agentlog-llm

Trace AI agent execution — LLM calls, tool calls, costs and latency. Zero dependencies.

pip install agentlog-llm

The Problem

Agentic AI systems make multiple LLM calls, use tools, make decisions — all invisibly. When something goes wrong (or costs too much), you have no idea what happened inside.

agentlog-llm gives you a complete execution trace — every LLM call, every tool use, every decision — with costs, latency, and token counts.

Quick Start

from agentlog import AgentTracer

tracer = AgentTracer("my-agent", task="Summarize documents")

# Log an LLM call
with tracer.llm_call("openai", "gpt-4o", prompt="Summarize this...") as call:
    response = openai_client.chat(...)
    call.response = response.text
    call.tokens_in = response.usage.prompt_tokens
    call.tokens_out = response.usage.completion_tokens

# Log a tool call
with tracer.tool_call("web_search", inputs={"query": "AI news"}) as tool:
    result = search("AI news")
    tool.output = result

# Log a decision
tracer.log("Decided to summarize top 3 results only")

# Finish and get trace
trace = tracer.finish(success=True)
print(trace.summary())

Output:

{
    "trace_id": "a1b2c3d4",
    "agent": "my-agent",
    "task": "Summarize documents",
    "steps": 3,
    "llm_calls": 1,
    "tool_calls": 1,
    "total_tokens": 1250,
    "total_cost_usd": 0.00425,
    "total_latency_ms": 2340.5,
    "success": True
}

Decorator Support

@tracer.trace_tool("calculator")
def calculate(expression: str) -> float:
    return eval(expression)

# Tool call is automatically logged
result = calculate("2 + 2")

Export

# As dict
data = tracer.to_dict()

# As JSON string
json_str = tracer.to_json()

# Save to file
tracer.save("trace.json")

AgentTrace Properties

trace.total_llm_calls     # Number of LLM calls
trace.total_tool_calls    # Number of tool calls
trace.total_tokens        # Total tokens used
trace.total_cost_usd      # Total cost in USD
trace.total_latency_ms    # Total latency in ms
trace.llm_calls           # List of LLMCall objects
trace.tool_calls          # List of ToolCall objects
trace.summary()           # Dict summary

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentlog_llm-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentlog_llm-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file agentlog_llm-0.1.0.tar.gz.

File metadata

  • Download URL: agentlog_llm-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for agentlog_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8508769258e0edf5094631b125a45fe3ee2b65e5f43d582ebb69f544ed157a93
MD5 e6bbc008e5bd573b9fba60b6f7a23af0
BLAKE2b-256 e7a13a8591228225fc2bda32b6ad31ab66d6758ee28b06c358896b26c712a520

See more details on using hashes here.

File details

Details for the file agentlog_llm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentlog_llm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for agentlog_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 414756128df51af6fac7680900ba5660d806f93eb33be70bbb92e0d5760e3d93
MD5 4fa0a24c3efe6328f50cd1fbfe5f99b3
BLAKE2b-256 a6e72129fe6ab38b4135a8bd14c3afad3a3de1e94844caed1ffe832086286fc7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page