Skip to main content

A lightweight, local-first agentic framework with tool calling, recursive sub-agents, and full execution tracing.

Project description

๐Ÿค– TrajectoryKit: An Agent Starter Pack

A lightweight, local-first agentic framework for HuggingFace models with built-in tool calling, recursive sub-agents, and full execution tracing.

License: MIT Python 3.12

๐ŸŽ๐Ÿ’จ Quickstart

from trajectorykit import dispatch

result = dispatch(
    user_input="Compare the stats of Blue Eyes White Dragon vs Dark Magician",
    turn_length=5,
    verbose=True
)

print(result["final_response"])

The agent writes and executes code in a sandbox, returning results with inline images:

Yu-Gi-Oh Card Stats Comparison

โœจ Features

  • ๐Ÿ  100% Local โ€” runs on your own GPU via vLLM, no API keys needed
  • ๐Ÿ”„ Agentic Loop โ€” iterative tool calling until the task is done
  • ๐Ÿค– Recursive Sub-Agents โ€” spawn child agents to decompose complex tasks (up to 3 levels deep)
  • ๐Ÿ’ป Sandboxed Code Execution โ€” run Python (and 40+ languages) in an Apptainer sandbox with file I/O
  • ๐Ÿ” Web Search โ€” built-in Google search via SerpAPI
  • ๐Ÿ“Š Full Execution Tracing โ€” every turn, tool call, token count, and sub-agent is recorded
  • ๐ŸŒ HTML Trace Viewer โ€” self-contained dark-themed trace pages with collapsible reasoning, inline images, and token stats

๐Ÿ“ฆ Package Structure

src/trajectorykit/
โ”œโ”€โ”€ __init__.py       # Public API: dispatch, EpisodeTrace, render_trace_html, render_trace_file
โ”œโ”€โ”€ config.py         # Model, API URL, traces directory, system prompt
โ”œโ”€โ”€ agent.py          # Core agentic loop with tool dispatch and trace building
โ”œโ”€โ”€ tool_store.py     # Tool definitions + wrapper functions
โ”œโ”€โ”€ tracing.py        # Dataclasses, pretty-print, JSON/HTML serialization
โ”œโ”€โ”€ examples.py       # Ready-to-run examples
โ””โ”€โ”€ serve_vllm.sh     # Script to launch vLLM server
traces/               # Auto-created directory for saved traces (JSON + HTML)

๐Ÿ›  Built-in Tools

Tool Description
execute_code Run code in a sandboxed Apptainer container. Supports file upload (files) and retrieval (fetch_files) as base64.
search_web Google search via SerpAPI. Returns titles, snippets, and links.
get_current_time Returns the current date and time.
add_numbers Adds two numbers (demo tool).
spawn_agent Spawns a recursive sub-agent with its own tool access and trace.

๐Ÿ” Recursive Sub-Agents

Dispatch can spawn child agents to handle subtasks independently. Each sub-agent runs its own agentic loop with full tool access and produces its own trace, nested inside the parent's trace tree.

from trajectorykit import dispatch

result = dispatch(
    user_input=(
        "How has the market price of the card 'Blue-Eyes White Dragon' moved over the last years?"
    ),
    turn_length=5,
    max_tokens=4096
)

result["trace"].pretty_print()

Max recursion depth is controlled by MAX_RECURSION_DEPTH in config.py (default: 3).

๐Ÿ“œ Tracing

Every dispatch() call returns a full execution trace in result["trace"].

Pretty-print to terminal

result["trace"].pretty_print()
๐Ÿ Agent [root]  trace_id=154b9f2e
  Input: What is the current time? What is 123 + 456?
  Duration: 8.42s | Turns: 2 | Tool calls: 2
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  โ”Œโ”€ Turn 1 (4.00s)
  โ”‚  ๐Ÿ”ง get_current_time({}) [0.01s]
  โ”‚     โ†’ 2026-02-19 21:04:29
  โ”‚  ๐Ÿ”ง add_numbers({"a": 123, "b": 456}) [0.00s]
  โ”‚     โ†’ 579
  โ””โ”€
  ...
๐Ÿ“Š Episode Summary:
  Prompt tokens:        3,621
  Completion tokens:    686
  Total tokens:         4,307

Save to disk

path = result["trace"].save()
# Writes traces/trace_20260219_210429_154b9f2e.json
# Also writes traces/trace_20260219_210429_154b9f2e.html

Traces are saved to the traces/ directory automatically.

HTML trace viewer

The HTML file is a self-contained dark-themed page with:

  • Prompt at the top (always visible)
  • Stats bar โ€” duration, turns, tool calls, sub-agents, total tokens (prompt + completion)
  • Collapsible trace detail โ€” starts collapsed, expand to drill into turns
  • Reasoning dropdowns โ€” model chain-of-thought shown per turn
  • Inline images โ€” plots and generated images rendered directly
  • Final response at the bottom (always visible)

You can also render any trace JSON to HTML:

from trajectorykit import render_trace_file

render_trace_file("traces/trace_20260219_210429_154b9f2e.json")

โš™๏ธ Configuration

All settings live in config.py:

Setting Default Description
MODEL_NAME Qwen/Qwen3-8B HuggingFace model served by vLLM
VLLM_API_URL http://localhost:3030/v1 vLLM OpenAI-compatible endpoint
MAX_RECURSION_DEPTH 3 Max sub-agent nesting depth
TRACES_DIR <repo_root>/traces/ Where .json and .html traces are saved

๐Ÿš€ Running

1. Install conda env

conda env create -f environment. yml.

2. Start the Apptainer sandbox (code execution)

bash src/trajectorykit/apptainer.sh

This pulls and runs the SandboxFusion container, exposing a code execution API on http://localhost:8080.

3. Start vLLM

bash src/trajectorykit/serve_vllm.sh

4. Run an example

cd src && python -m trajectorykit.examples

API

result = dispatch(
    user_input="Your task here",
    turn_length=5,          # Max turns (None = unlimited)
    verbose=True,           # Print turn-by-turn output
    max_tokens=2000,        # Max tokens per generation
    temperature=0.7,        # Sampling temperature
)

# result keys:
result["final_response"]   # str โ€” the model's final answer
result["turns"]            # int โ€” number of turns taken
result["tool_calls"]       # int โ€” total tool calls made
result["messages"]         # list โ€” full conversation history
result["trace"]            # EpisodeTrace โ€” full execution tree

๐Ÿ“š Citation

If you use TrajectoryKit in your research or project, please cite it:

@software{trajectorykit2026,
  title={TrajectoryKit: An Agent Starter Pack},
  author={Lugoloobi, William},
  year={2026},
  url={https://github.com/KabakaWilliam/TrajectoryKit}
}

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

trajectorykit-0.1.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

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

trajectorykit-0.1.0-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for trajectorykit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0265cdf53438859e69f49480c574f0bd2f7136dab909590cf94638c8eb93484f
MD5 2f7548f9a4cc62e35253a7ef150aadfb
BLAKE2b-256 c0372f394f8f6424f52b158f5eec454608aba98d7e877e7816cb44e1350db34f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for trajectorykit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25741d74ec7dc178363ab55071e2a225f8276401a996bad28e7197bba9939e3d
MD5 5f1696963f8daa18c3a238797a14fc14
BLAKE2b-256 73af2991fb8294ca84206b5d97724d4b97304957eb8c94c17b96d232c12a46bb

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