This repository is a local testing project for a conversational AI agent focused on small Python coding and debugging tasks. It uses a classic ReAct loop, DeepSeek through the OpenAI-compatible SDK, JSON-mode assistant outputs for both reasoning and tool decisions, a Docker-backed python tool, a safe calculator tool, sliding-window context management, and detailed JSONL trace logging.
- Conversational CLI agent with persistent session history
- Sliding-window context management across turns
- JSON-based ReAct protocol with full
thought,thought_summary,action,action_input, andfinal_answer - Docker-isolated Python execution with no network and no host file access
- Calculator tool with arithmetic and math functions such as
sqrt,sin, andlog - Detailed per-session JSONL traces plus a formatter for human-readable replay
- YAML-based configuration for model settings and stopping thresholds
- Prompt definitions kept in
src/prompts.py
config.yaml: adjustable runtime configurationkeys.cfg: DeepSeek API key filesrc/: implementation modulestests/: focused unit teststraces/: generated per-session JSONL tracessessions/: persisted conversation memoryPROJECT.md: detailed design notes
- Create a virtual environment if you want one.
- Install the runtime dependencies into your current Python environment:
pip install openai PyYAML- Make sure
keys.cfgcontains your DeepSeek key in YAML form:
DEEPSEEK_API_KEY: your_key_here- Make sure Docker is installed and the daemon is running.
- Optionally pre-pull the configured Python image:
docker pull python:3.11-slimThe Python tool depends on local Docker availability. The current implementation runs containers with:
--network none--read-only--cap-drop ALL--security-opt no-new-privileges- CPU, memory, and process limits from
config.yaml - no host volume mounts
This is a good local testing sandbox, but it is not a formally hardened security boundary. For higher-risk workloads, you would want a stronger isolation layer than plain Docker.
The CLI uses argparse subcommands. The current command shape is:
python main.py [--config CONFIG] {chat,format-trace} ...Command-specific argument rules:
chatstarts the interactive agent sessionchataccepts optional--session-idor-Sformat-tracerequires one positional argument,trace_pathformat-traceaccepts optional--outputor-O
Start an interactive chat session:
python main.py chatResume or create a named session:
python main.py chat --session-id study-session
python main.py chat -S study-sessionRender a JSONL trace into readable text:
python main.py format-trace traces/<trace-file>.jsonlWrite the formatted trace to a file:
python main.py format-trace traces/<trace-file>.jsonl --output trace_report.txt
python main.py format-trace traces/<trace-file>.jsonl -O trace_report.txtAll adjustable settings live in config.yaml. The most important ones are:
llm.modelllm.temperatureagent.max_steps_per_queryagent.max_repeated_failuresagent.sliding_window_turnstools.python.docker_imagetools.python.timeout_secondstools.python.memory_limittools.python.cpu_limittools.python.pids_limit
Run the local unit tests with:
PYTHONPATH=src python -m unittest discover -s testsThe included tests focus on parsing, config loading, sliding-window memory, calculator behavior, and trace formatting. They do not require a live DeepSeek call or a running Docker daemon.
- The final user answer is printed in human-readable form.
- Each session appends to one JSONL trace file in
traces/<session-id>.jsonl. - Session state is stored in
sessions/<session-id>.json. - The session record stores the invariant system prompt used for that session.
- Prompt definitions live in
src/prompts.py. - The main runtime entrypoint is
python main.py.