MCPcopy Index your code
hub / github.com/PeterLeeXX/Socrates

github.com/PeterLeeXX/Socrates @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
118 symbols 450 edges 21 files 40 documented · 34%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Socrates

Small Python coding agent for the terminal. It uses LiteLLM for model access, Rich for terminal output, and a compact built-in toolset for reading, editing, searching, and running code.

Socrates is intentionally simple: the core agent loop lives in a handful of files, the tool schemas are plain Python, and the runtime is easy to inspect or extend.

Features

  • Multi-provider model registry via LiteLLM
  • Streaming terminal responses
  • Tool-calling agent loop
  • Built-in tools for shell, file read/write/edit, glob, and grep
  • Parallel execution for multiple tool calls
  • Context compression for long sessions
  • Session save/resume
  • .env support from the current working directory and ~/.socrates/.env
  • Dangerous shell command blocking for common footguns

Install

pip install socrates

For local development:

git clone https://github.com/PeterLeeXX/Socrates.git
cd Socrates
pip install -e ".[dev]"
pytest -q

Quick Start

Set an API key for the provider you want to use:

export DEEPSEEK_API_KEY=sk-...
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-...
export GEMINI_API_KEY=...

Start the interactive REPL:

socrates

Use a specific model:

socrates -m qwen3.6-plus
socrates -m gpt-5.5
socrates -m claude-sonnet-4.6
socrates -m gemini-3.5-flash

Run one prompt and exit:

socrates "find the failing test and fix it"
socrates -p "summarize the project structure"

Resume a saved session:

socrates --resume SESSION_ID

Configuration

Socrates loads .env from:

  1. The current working directory
  2. ~/.socrates/.env

Common variables:

Variable Purpose
SOCRATES_MODEL Default model registry key
SOCRATES_<PROVIDER>_API_KEY Provider-specific API key override
SOCRATES_<PROVIDER>_API_BASE Provider-specific API base override
DEEPSEEK_API_KEY DeepSeek API key
OPENAI_API_KEY OpenAI API key
ANTHROPIC_API_KEY Anthropic API key
GEMINI_API_KEY Gemini API key
DASHSCOPE_API_KEY Qwen/DashScope API key
MOONSHOT_API_KEY Moonshot/Kimi API key
ZAI_API_KEY Z.ai/GLM API key

Example:

SOCRATES_MODEL=deepseek-v4-flash
DEEPSEEK_API_KEY=sk-...

Model Keys

Use /models inside the REPL to see the current registry.

Common keys:

Key Provider
deepseek-v4-flash DeepSeek
deepseek-v4-pro DeepSeek
qwen3.6-plus Qwen/DashScope
qwen3.6-flash Qwen/DashScope
gpt-5.5 OpenAI
gpt-5.5-pro OpenAI
claude-sonnet-4.6 Anthropic
claude-opus-4.7 Anthropic
gemini-3.5-flash Google Gemini
kimi-k2.6 Moonshot/Kimi
glm-5.1 Z.ai

Tools

The model can call these built-in tools:

Tool Purpose
bash Run shell commands with safety checks and cwd tracking
read_file Read text files with line numbers, offset, and limit
write_file Create or overwrite files
edit_file Replace exact text and return a unified diff
glob Find files by glob pattern
grep Search text files with regex

REPL Commands

Command Description
/help Show help
/model Show the current model
/model <key> Switch model
/models List registered model keys
/tokens Show token and cost estimate
/diff Show files modified by write/edit tools
/compact Compress the current conversation context
/save [name] Save the session
/sessions List saved sessions
/clear Clear conversation history except the system prompt
/quit Exit

Input controls:

  • Enter sends the message
  • Esc+Enter inserts a newline
  • Ctrl+C cancels the current input or run
  • Ctrl+D exits

Architecture

socrates/
  cli.py              REPL, one-shot mode, slash commands
  agent.py            Agent loop, LLM calls, tool execution
  llm.py              LiteLLM wrapper and streaming chunk normalization
  context.py          Message history and compression
  config.py           Model registry and environment configuration
  session.py          Local session save/load/list helpers
  prompts/system.py   System prompt
  tools/              Built-in tool implementations

The runtime flow is:

  1. Add the user message to context
  2. Send messages and tool schemas to the model
  3. Stream assistant text to the terminal
  4. Execute tool calls when requested
  5. Append tool results to context
  6. Repeat until the model returns without tool calls

Context compression happens when the conversation approaches the configured token threshold. Socrates first truncates older long tool outputs, then summarizes older turns if needed.

AG-UI Status

ag-ui-protocol is listed as a dependency because Socrates is being prepared for an AG-UI event adapter. The current CLI does not yet expose an AG-UI HTTP/SSE endpoint, assistant-ui frontend, or Tauri desktop shell.

The intended direction is a thin adapter:

Socrates agent loop -> internal agent events -> AG-UI BaseEvent stream -> assistant-ui

Library Use

from socrates import Agent, Config

config = Config.from_env()
config.resolve_model("deepseek-v4-flash")

agent = Agent(config)
agent.run("inspect the tests and explain what they cover")

Tests

pytest -q

License

MIT. See LICENSE.

Core symbols most depended-on inside this repo

execute
called by 25
socrates/tools/bash.py
add
called by 19
socrates/context.py
resolve_model
called by 12
socrates/config.py
run
called by 6
socrates/agent.py
load_session
called by 6
socrates/session.py
save_session
called by 5
socrates/session.py
compress
called by 4
socrates/context.py
get_messages
called by 2
socrates/context.py

Shape

Function 68
Method 37
Class 13

Languages

Python100%

Modules by API surface

tests/test_core.py49 symbols
socrates/context.py10 symbols
socrates/agent.py9 symbols
socrates/llm.py8 symbols
socrates/cli.py7 symbols
socrates/session.py6 symbols
socrates/tools/grep_tool.py5 symbols
socrates/tools/bash.py4 symbols
socrates/config.py4 symbols
socrates/tools/read_file.py3 symbols
socrates/tools/edit_file.py3 symbols
socrates/tools/base.py3 symbols

For agents

$ claude mcp add Socrates \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact