Skip to main content

Record AI agent decisions, including phantom branches, latency, and costs.

Project description

Overwriting the file as intended to improve the repository presentation.

👻 GhostTrace

PyPI version License: MIT Python Versions

GhostTrace is a lightweight Python library designed to record the "roads not taken" by your AI agents. It captures rejected alternatives (phantom branches), tracks their latency, and estimates API costs, providing deep insights into your agent's decision-making process.


✨ Features

  • 🛤️ Phantom Branch Tracking: Record every alternative decision your agent considered but rejected.
  • 💰 Cost Estimation: Automatically calculate estimated USD costs for various LLM models (GPT-4, Claude-3, etc.).
  • ⏱️ Latency Monitoring: Measure the time taken for each decision branch.
  • 📄 JSON Exports: Save traces to a structured .ghost.json format for later analysis or replaying.
  • 💻 Interactive CLI: Replay agent sessions in your terminal with rich, formatted output.

🚀 Installation

Install GhostTrace via pip:

pip install ghosttrace

🛠️ Quick Start

Basic Usage

from ghosttrace.ghost_writer import GhostWriter

# Initialize the writer
writer = GhostWriter(output_dir='.')

def my_evaluate_fn(decision, context):
    # Your logic to evaluate a decision
    if "risky" in decision:
        return {"status": "rejected", "reason": "Too risky for production"}
    return {"status": "accepted"}

# Evaluate and record a decision with tracking
result = writer.evaluate_and_record(
    decision="Update database schema directly",
    evaluate_fn=my_evaluate_fn,
    context={"env": "production"},
    input_tokens=1200,
    output_tokens=400,
    model="gpt-4-turbo"
)

Using the CLI

GhostTrace comes with a built-in CLI to replay your agent's traces:

# Run a mock recording session
ghosttrace record --goal "Refactor auth module"

# Replay the session
ghosttrace replay <session_id>.ghost.json

# Show phantom branches (the roads not taken)
ghosttrace replay <session_id>.ghost.json --show-phantoms

📊 Supported Models for Cost Tracking

GhostTrace supports cost estimation for popular models including:

  • OpenAI: gpt-4, gpt-4-turbo, gpt-3.5-turbo
  • Anthropic: claude-3-opus, claude-3-sonnet, claude-3-haiku
  • Custom: Default pricing available for other models.

🤝 Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request to help improve GhostTrace.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with 👻 by Ahmed Allam

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

ghosttrace-0.3.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

ghosttrace-0.3.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file ghosttrace-0.3.1.tar.gz.

File metadata

  • Download URL: ghosttrace-0.3.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for ghosttrace-0.3.1.tar.gz
Algorithm Hash digest
SHA256 1897af8c35e7ee6245c7ce626cde5da9b8bde4ea8c0d7e1dc3878ffb1af118fc
MD5 070f05d3a2595c742125248e1abdeeea
BLAKE2b-256 147835c55ac464be4dade84796399584a7f6b388a35b03ca1dbac1f19db37649

See more details on using hashes here.

File details

Details for the file ghosttrace-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: ghosttrace-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for ghosttrace-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7f6f4c534e762f9108f2eba7676d2b71d717b0db131f20c9a74ed9bb318b18f
MD5 73052ab84f05cf55a0f3d01dc647d810
BLAKE2b-256 87f01c99a5262df1d014ac1494881073a158958b9c705bbed3d8287bfcfd2796

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