agentic-python-coder 2.0.1__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/.gitignore +9 -4
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/PKG-INFO +157 -162
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/README.md +154 -161
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/__init__.py +10 -4
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/cli.py +13 -10
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/kernel.py +20 -16
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/llm.py +190 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/mcp_server.py +485 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/models/deepseek31.json +7 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/models/gemini25.json +8 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/models/gpt5.json +6 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/models/grok41.json +7 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/models/opus45.json +6 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/models/qwen3.json +7 -0
- agentic_python_coder-2.2.0/coder/src/agentic_python_coder/models/sonnet45.json +6 -0
- agentic_python_coder-2.2.0/coder/tests/test_kernel.py +193 -0
- agentic_python_coder-2.2.0/coder/tests/test_library_api.py +155 -0
- agentic_python_coder-2.2.0/coder/tests/test_mcp_server.py +327 -0
- agentic_python_coder-2.2.0/coder/tests/test_todo_flag_integration.py +128 -0
- agentic_python_coder-2.2.0/coder/tests/test_todo_tool_availability.py +49 -0
- agentic_python_coder-2.2.0/coder-examples/cpmpy/cpmpy.md +48 -0
- agentic_python_coder-2.2.0/examples/cpmpy/README.md +69 -0
- agentic_python_coder-2.2.0/examples/cpmpy/sample_problems/magic_square.md +46 -0
- agentic_python_coder-2.2.0/examples/cpmpy/sample_problems/n_queens.md +36 -0
- agentic_python_coder-2.2.0/examples/regex/sample_tasks/test_email/email_extractor.py +77 -0
- agentic_python_coder-2.2.0/examples/regex/sample_tasks/test_email/extracted_emails.txt +7 -0
- agentic_python_coder-2.2.0/examples/regex/sample_tasks/test_email/text.txt +1 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/pyproject.toml +4 -1
- agentic_python_coder-2.0.1/coder/src/agentic_python_coder/llm.py +0 -230
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/LICENSE +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/.gitignore +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/prompts/system.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/prompts/system_todo.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/agent.py +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/__init__.py +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/clingo/README.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/clingo/clingo.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/bird_reasoning.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/diagnosis.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/simple_coloring.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/stable_marriage.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/sudoku_mini.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0/coder/src/agentic_python_coder}/examples/cpmpy/README.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/cpmpy/cpmpy.md +0 -0
- {agentic_python_coder-2.0.1/examples/cpmpy/sample_problems → agentic_python_coder-2.2.0/coder/src/agentic_python_coder/examples/cpmpy/sample_tasks}/magic_square.md +0 -0
- {agentic_python_coder-2.0.1/examples/cpmpy/sample_problems → agentic_python_coder-2.2.0/coder/src/agentic_python_coder/examples/cpmpy/sample_tasks}/n_queens.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/regex/README.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/regex/regex.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/regex/sample_tasks/email_extraction.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/regex/sample_tasks/phone_validation.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/examples/regex/sample_tasks/url_parsing.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/project_md.py +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/runner.py +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/coder/src/agentic_python_coder/tools.py +0 -0
- {agentic_python_coder-2.0.1/coder/src/agentic_python_coder/examples → agentic_python_coder-2.2.0/coder-examples}/cpmpy/README.md +0 -0
- {agentic_python_coder-2.0.1/coder/src/agentic_python_coder/examples → agentic_python_coder-2.2.0/coder-examples}/cpmpy/sample_tasks/magic_square.md +0 -0
- {agentic_python_coder-2.0.1/coder/src/agentic_python_coder/examples → agentic_python_coder-2.2.0/coder-examples}/cpmpy/sample_tasks/n_queens.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/clingo/README.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/clingo/clingo.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/clingo/sample_tasks/bird_reasoning.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/clingo/sample_tasks/diagnosis.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/clingo/sample_tasks/simple_coloring.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/clingo/sample_tasks/stable_marriage.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/clingo/sample_tasks/sudoku_mini.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/cpmpy/cpmpy.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/regex/README.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/regex/regex.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/regex/sample_tasks/email_extraction.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/regex/sample_tasks/phone_validation.md +0 -0
- {agentic_python_coder-2.0.1 → agentic_python_coder-2.2.0}/examples/regex/sample_tasks/url_parsing.md +0 -0
|
@@ -153,6 +153,7 @@ uv.lock
|
|
|
153
153
|
|
|
154
154
|
# Project specific
|
|
155
155
|
CLAUDE-archive.md
|
|
156
|
+
PROCESS_NOTES.md
|
|
156
157
|
conversation_log.json
|
|
157
158
|
coder_output.log
|
|
158
159
|
task.md
|
|
@@ -164,15 +165,19 @@ TRASH/
|
|
|
164
165
|
LOCAL/
|
|
165
166
|
ASP/
|
|
166
167
|
CPBENCH/
|
|
168
|
+
CPMPY/
|
|
167
169
|
PAPER/
|
|
170
|
+
PAPER-ASP/
|
|
171
|
+
ZEBRA/
|
|
172
|
+
.mcp.json
|
|
168
173
|
examples/cpmpy/cpmpy_v*.md
|
|
169
174
|
examples/cpmpy/cpmpy.md.backup-*
|
|
170
175
|
examples/clingo/clingo_v*.md
|
|
171
176
|
|
|
172
|
-
# Test files and folders
|
|
173
|
-
test-*/
|
|
174
|
-
test_*.py
|
|
175
|
-
test_*/
|
|
177
|
+
# Test files and folders (root level only)
|
|
178
|
+
/test-*/
|
|
179
|
+
/test_*.py
|
|
180
|
+
/test_*/
|
|
176
181
|
PROBLEM.md
|
|
177
182
|
*.log
|
|
178
183
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agentic-python-coder
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: A lightweight Python coding agent that writes, executes, and iterates on code through natural language instructions
|
|
5
5
|
Author: Stefan Szeider
|
|
6
6
|
License: Apache-2.0
|
|
@@ -21,6 +21,7 @@ Requires-Dist: langchain-core>=1.1.0
|
|
|
21
21
|
Requires-Dist: langchain-experimental>=0.4.0
|
|
22
22
|
Requires-Dist: langchain-openai>=1.1.0
|
|
23
23
|
Requires-Dist: langgraph>=1.0.4
|
|
24
|
+
Requires-Dist: mcp>=1.0.0
|
|
24
25
|
Requires-Dist: python-dotenv>=1.2.1
|
|
25
26
|
Requires-Dist: pyyaml>=6.0.3
|
|
26
27
|
Requires-Dist: rich>=14.2.0
|
|
@@ -28,6 +29,7 @@ Provides-Extra: dev
|
|
|
28
29
|
Requires-Dist: mypy>=1.19.0; extra == 'dev'
|
|
29
30
|
Requires-Dist: ruff>=0.14.7; extra == 'dev'
|
|
30
31
|
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest-asyncio>=1.2.0; extra == 'test'
|
|
31
33
|
Requires-Dist: pytest-cov>=7.0.0; extra == 'test'
|
|
32
34
|
Requires-Dist: pytest-watch>=4.2.0; extra == 'test'
|
|
33
35
|
Requires-Dist: pytest>=9.0.1; extra == 'test'
|
|
@@ -37,10 +39,16 @@ Description-Content-Type: text/markdown
|
|
|
37
39
|
|
|
38
40
|
[](https://www.python.org/downloads/)
|
|
39
41
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
42
|
+
[](https://modelcontextprotocol.io/)
|
|
40
43
|
[](https://github.com/astral-sh/uv)
|
|
41
44
|
[](https://github.com/langchain-ai/langgraph)
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
This package provides two utilities for Python code execution:
|
|
47
|
+
|
|
48
|
+
1. **coder** — An autonomous coding agent using the ReAct framework (CLI + Python library)
|
|
49
|
+
2. **ipython_mcp** — An MCP server that gives any MCP-compatible client (Claude Desktop, etc.) Python execution capability
|
|
50
|
+
|
|
51
|
+
Both share a persistent IPython kernel for stateful code execution.
|
|
44
52
|
|
|
45
53
|
For details on architecture and constraint modelling applications, see [[Szeider 2025, arxiv-2508.07468]](https://arxiv.org/abs/2508.07468).
|
|
46
54
|
|
|
@@ -50,52 +58,136 @@ For details on architecture and constraint modelling applications, see [[Szeider
|
|
|
50
58
|
|
|
51
59
|
- Python 3.13
|
|
52
60
|
- UV package manager: `curl -LsSf https://astral.sh/uv/install.sh | sh`
|
|
53
|
-
- OpenRouter API key from [openrouter.ai](https://openrouter.ai)
|
|
54
61
|
|
|
55
|
-
###
|
|
62
|
+
### For the Coding Agent
|
|
56
63
|
|
|
57
64
|
```bash
|
|
58
65
|
# Install as CLI tool
|
|
59
66
|
uv tool install agentic-python-coder
|
|
60
67
|
|
|
61
|
-
# Set up API key
|
|
68
|
+
# Set up OpenRouter API key
|
|
62
69
|
mkdir -p ~/.config/coder
|
|
63
70
|
echo 'OPENROUTER_API_KEY="your-key-here"' > ~/.config/coder/.env
|
|
64
71
|
```
|
|
65
72
|
|
|
66
|
-
|
|
73
|
+
Get your API key from [openrouter.ai](https://openrouter.ai).
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
# Add to your project
|
|
70
|
-
uv add agentic-python-coder
|
|
75
|
+
### For the MCP Server
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
uv pip install agentic-python-coder
|
|
74
|
-
```
|
|
77
|
+
No installation required — use `uvx` to run directly. See [MCP Server Configuration](#mcp-server-configuration).
|
|
75
78
|
|
|
76
|
-
|
|
77
|
-
- Pass directly: `solve_task(..., api_key="sk-or-...")`
|
|
78
|
-
- Environment variable: `export OPENROUTER_API_KEY="sk-or-..."`
|
|
79
|
-
- Config file: `~/.config/coder/.env` (same as CLI)
|
|
79
|
+
---
|
|
80
80
|
|
|
81
81
|
## Quick Start
|
|
82
82
|
|
|
83
|
-
###
|
|
83
|
+
### Option A: Autonomous Agent
|
|
84
84
|
|
|
85
85
|
```bash
|
|
86
86
|
# Simple task
|
|
87
87
|
coder "Create a function that calculates factorial"
|
|
88
88
|
|
|
89
|
-
#
|
|
89
|
+
# With packages and project template
|
|
90
|
+
coder --with cpmpy --project coder-examples/cpmpy/cpmpy.md "Solve 8-queens"
|
|
91
|
+
|
|
92
|
+
# Interactive mode
|
|
93
|
+
coder -i
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Option B: MCP Server
|
|
97
|
+
|
|
98
|
+
Add to your Claude Desktop MCP configuration:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"mcpServers": {
|
|
103
|
+
"ipython": {
|
|
104
|
+
"command": "uvx",
|
|
105
|
+
"args": ["--from", "agentic-python-coder", "ipython_mcp"]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Then ask Claude Desktop to execute Python code — it will use the persistent IPython session.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## The Coding Agent
|
|
116
|
+
|
|
117
|
+
### CLI Usage
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Inline task
|
|
121
|
+
coder "your task"
|
|
122
|
+
|
|
123
|
+
# Task from file (creates {basename}_code.py and {basename}.jsonl)
|
|
90
124
|
coder --task problem.md
|
|
91
125
|
|
|
92
|
-
#
|
|
126
|
+
# Specify working directory
|
|
127
|
+
coder --dir results/test1 "your task"
|
|
128
|
+
|
|
129
|
+
# Interactive mode
|
|
130
|
+
coder -i
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### CLI Options
|
|
134
|
+
|
|
135
|
+
| Flag | Description |
|
|
136
|
+
|------|-------------|
|
|
137
|
+
| `--version`, `-V` | Show version and exit |
|
|
138
|
+
| `--init [TEMPLATE]` | Initialize example templates (cpmpy, clingo, regex, or all) |
|
|
139
|
+
| `--task`, `-t FILE` | Load task from markdown file |
|
|
140
|
+
| `--model MODEL` | Model name or JSON file (default: sonnet45) |
|
|
141
|
+
| `--project`, `-p FILE` | Project template for domain-specific prompts |
|
|
142
|
+
| `--with PACKAGE` | Add packages dynamically (repeatable) |
|
|
143
|
+
| `--dir`, `-d DIR` | Working directory |
|
|
144
|
+
| `--api-key KEY` | Override API key |
|
|
145
|
+
| `--todo` | Enable task tracking tool |
|
|
146
|
+
| `--quiet`, `-q` | Suppress console output |
|
|
147
|
+
| `--step-limit N` | Max agent steps (default: 200) |
|
|
148
|
+
| `-i`, `--interactive` | Interactive conversation mode |
|
|
149
|
+
|
|
150
|
+
### Model Selection
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Built-in models (versioned names)
|
|
154
|
+
coder --model sonnet45 "task" # Claude Sonnet 4.5 (default)
|
|
155
|
+
coder --model opus45 "task" # Claude Opus 4.5
|
|
156
|
+
coder --model deepseek31 "task" # DeepSeek v3.1
|
|
157
|
+
coder --model grok41 "task" # X.AI Grok 4.1
|
|
158
|
+
coder --model qwen3 "task" # Qwen3 Coder
|
|
159
|
+
coder --model gemini25 "task" # Gemini Pro 2.5
|
|
160
|
+
coder --model gpt5 "task" # GPT-5
|
|
161
|
+
|
|
162
|
+
# Custom model (JSON file)
|
|
163
|
+
coder --model ./mymodel.json "task"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Project Templates
|
|
167
|
+
|
|
168
|
+
Domain-specific templates improve results:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Initialize example templates (creates coder-examples/ directory)
|
|
93
172
|
coder --init
|
|
94
173
|
|
|
95
|
-
#
|
|
174
|
+
# Constraint programming with CPMpy
|
|
96
175
|
coder --with cpmpy --project coder-examples/cpmpy/cpmpy.md "Solve 8-queens"
|
|
176
|
+
|
|
177
|
+
# Answer Set Programming with Clingo
|
|
178
|
+
coder --with clingo --project coder-examples/clingo/clingo.md "Model bird flight"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Interactive Mode
|
|
182
|
+
|
|
183
|
+
Interactive mode (`-i`) maintains a persistent session for multi-turn conversations:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
coder -i --project coder-examples/cpmpy/cpmpy.md --with cpmpy
|
|
97
187
|
```
|
|
98
188
|
|
|
189
|
+
State is preserved across turns. Type `exit` or `quit` to end.
|
|
190
|
+
|
|
99
191
|
### Library Usage
|
|
100
192
|
|
|
101
193
|
```python
|
|
@@ -105,8 +197,8 @@ import agentic_python_coder as coder
|
|
|
105
197
|
messages, stats, log_path = coder.solve_task(
|
|
106
198
|
"Write a fibonacci function",
|
|
107
199
|
working_directory="/tmp/workspace",
|
|
108
|
-
model="
|
|
109
|
-
quiet=True,
|
|
200
|
+
model="sonnet45",
|
|
201
|
+
quiet=True,
|
|
110
202
|
)
|
|
111
203
|
|
|
112
204
|
# Get the final response
|
|
@@ -114,13 +206,9 @@ response = coder.get_final_response(messages)
|
|
|
114
206
|
print(response)
|
|
115
207
|
```
|
|
116
208
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
## API Reference
|
|
209
|
+
### Library API Reference
|
|
120
210
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Run a complete coding task end-to-end. Recommended for most use cases.
|
|
211
|
+
#### `solve_task()` — High-Level API
|
|
124
212
|
|
|
125
213
|
```python
|
|
126
214
|
from agentic_python_coder import solve_task
|
|
@@ -128,7 +216,7 @@ from agentic_python_coder import solve_task
|
|
|
128
216
|
messages, stats, log_path = solve_task(
|
|
129
217
|
task="Your task description",
|
|
130
218
|
working_directory=".", # Where to run and save files
|
|
131
|
-
model=None, # Model
|
|
219
|
+
model=None, # Model name: "sonnet45", "opus45", or JSON file
|
|
132
220
|
system_prompt=None, # Custom system prompt (string)
|
|
133
221
|
system_prompt_path=None, # Path to system prompt file
|
|
134
222
|
project_prompt=None, # Domain-specific context
|
|
@@ -147,9 +235,7 @@ messages, stats, log_path = solve_task(
|
|
|
147
235
|
- `stats`: Dict with `tool_usage`, `token_consumption`, `execution_time_seconds`
|
|
148
236
|
- `log_path`: Path to saved log file (or None if `save_log=False`)
|
|
149
237
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
For custom workflows, multi-turn conversations, or fine-grained control.
|
|
238
|
+
#### `create_coding_agent()` / `run_agent()` — Low-Level API
|
|
153
239
|
|
|
154
240
|
```python
|
|
155
241
|
from agentic_python_coder import create_coding_agent, run_agent, get_final_response
|
|
@@ -158,7 +244,7 @@ from agentic_python_coder import create_coding_agent, run_agent, get_final_respo
|
|
|
158
244
|
agent = create_coding_agent(
|
|
159
245
|
working_directory="/tmp/workspace",
|
|
160
246
|
system_prompt="You are a Python expert.",
|
|
161
|
-
model="
|
|
247
|
+
model="deepseek31",
|
|
162
248
|
with_packages=["pandas"],
|
|
163
249
|
)
|
|
164
250
|
|
|
@@ -166,182 +252,91 @@ agent = create_coding_agent(
|
|
|
166
252
|
messages, stats = run_agent(agent, "Load data.csv", quiet=True)
|
|
167
253
|
messages2, stats2 = run_agent(agent, "Now plot column A", quiet=True)
|
|
168
254
|
|
|
169
|
-
# Extract response
|
|
170
255
|
print(get_final_response(messages2))
|
|
171
256
|
```
|
|
172
257
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
Get a configured LangChain LLM instance for custom use.
|
|
258
|
+
#### `get_openrouter_llm()` — LLM Access
|
|
176
259
|
|
|
177
260
|
```python
|
|
178
|
-
from agentic_python_coder import get_openrouter_llm,
|
|
179
|
-
|
|
180
|
-
# Get LLM by alias
|
|
181
|
-
llm = get_openrouter_llm(model="sonnet")
|
|
261
|
+
from agentic_python_coder import get_openrouter_llm, list_available_models
|
|
182
262
|
|
|
183
|
-
|
|
184
|
-
print(
|
|
185
|
-
#
|
|
263
|
+
llm = get_openrouter_llm(model="sonnet45")
|
|
264
|
+
print(list_available_models())
|
|
265
|
+
# ['deepseek31', 'gemini25', 'gpt5', 'grok41', 'opus45', 'qwen3', 'sonnet45']
|
|
186
266
|
```
|
|
187
267
|
|
|
188
268
|
---
|
|
189
269
|
|
|
190
|
-
##
|
|
270
|
+
## The MCP Server
|
|
191
271
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
```bash
|
|
195
|
-
# Inline task
|
|
196
|
-
coder "your task"
|
|
272
|
+
The `ipython_mcp` server provides Python code execution via the Model Context Protocol. Use it to give Claude Desktop (or any MCP-compatible client) the ability to run Python code in a persistent session.
|
|
197
273
|
|
|
198
|
-
|
|
199
|
-
coder --task problem.md
|
|
274
|
+
### MCP Server Configuration
|
|
200
275
|
|
|
201
|
-
|
|
202
|
-
coder --dir results/test1 "your task"
|
|
276
|
+
Add to your MCP settings (e.g., `~/.claude/claude_desktop_config.json` or project `.mcp.json`):
|
|
203
277
|
|
|
204
|
-
|
|
205
|
-
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"mcpServers": {
|
|
281
|
+
"ipython": {
|
|
282
|
+
"command": "uvx",
|
|
283
|
+
"args": ["--from", "agentic-python-coder", "ipython_mcp"]
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
206
287
|
```
|
|
207
288
|
|
|
208
|
-
###
|
|
289
|
+
### Available Tools
|
|
209
290
|
|
|
210
|
-
|
|
|
291
|
+
| Tool | Description |
|
|
211
292
|
|------|-------------|
|
|
212
|
-
|
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
|
|
|
216
|
-
| `--project`, `-p FILE` | Project template for domain-specific prompts |
|
|
217
|
-
| `--with PACKAGE` | Add packages dynamically (repeatable) |
|
|
218
|
-
| `--dir`, `-d DIR` | Working directory |
|
|
219
|
-
| `--api-key KEY` | Override API key |
|
|
220
|
-
| `--todo` | Enable task tracking tool |
|
|
221
|
-
| `--quiet`, `-q` | Suppress console output |
|
|
222
|
-
| `--step-limit N` | Max agent steps (default: 200) |
|
|
223
|
-
| `-i`, `--interactive` | Interactive conversation mode |
|
|
224
|
-
|
|
225
|
-
### Model Selection
|
|
226
|
-
|
|
227
|
-
```bash
|
|
228
|
-
coder --model sonnet "task" # Claude Sonnet 4.5 (default)
|
|
229
|
-
coder --model opus "task" # Claude Opus 4.5
|
|
230
|
-
coder --model deepseek "task" # DeepSeek v3.1
|
|
231
|
-
coder --model grok "task" # X.AI Grok
|
|
232
|
-
coder --model qwen "task" # Qwen3 Coder
|
|
233
|
-
coder --model gemini "task" # Gemini Pro 2.5
|
|
234
|
-
coder --model gpt "task" # GPT-5
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
### Project Templates
|
|
238
|
-
|
|
239
|
-
Domain-specific templates improve results. First, initialize the examples:
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
# Initialize all example templates (creates coder-examples/ directory)
|
|
243
|
-
coder --init
|
|
244
|
-
|
|
245
|
-
# Or initialize only specific templates
|
|
246
|
-
coder --init cpmpy
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
Then use them:
|
|
250
|
-
|
|
251
|
-
```bash
|
|
252
|
-
# Constraint programming
|
|
253
|
-
coder --with cpmpy --project coder-examples/cpmpy/cpmpy.md "Solve 8-queens"
|
|
293
|
+
| `python_exec` | Execute Python code. Auto-starts session if needed. Default 30s timeout. |
|
|
294
|
+
| `python_reset` | Clear session state. Optionally install packages (e.g., `packages=["numpy", "pandas"]`). |
|
|
295
|
+
| `python_status` | Check if session is active, Python version, installed packages, defined variables. |
|
|
296
|
+
| `python_interrupt` | Send interrupt signal to stop long-running code. Session state is preserved. |
|
|
254
297
|
|
|
255
|
-
|
|
256
|
-
coder --with cpmpy --project coder-examples/cpmpy/cpmpy.md \
|
|
257
|
-
--task coder-examples/cpmpy/sample_tasks/n_queens.md
|
|
298
|
+
### Features
|
|
258
299
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
300
|
+
- **Persistent state**: Variables, imports, and definitions persist across executions
|
|
301
|
+
- **Auto-start**: Session starts automatically on first `python_exec`
|
|
302
|
+
- **Package installation**: Use `python_reset` with `packages` parameter to install dependencies
|
|
303
|
+
- **Timeout handling**: Long-running code times out gracefully (session preserved)
|
|
304
|
+
- **Interrupt support**: Stop runaway code without losing session state
|
|
262
305
|
|
|
263
|
-
###
|
|
306
|
+
### Usage Tips
|
|
264
307
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
```bash
|
|
268
|
-
# Start interactive session
|
|
269
|
-
coder -i
|
|
270
|
-
|
|
271
|
-
# With project template
|
|
272
|
-
coder -i --project coder-examples/cpmpy/cpmpy.md --with cpmpy
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
**Features:**
|
|
276
|
-
- Persistent IPython kernel (state preserved across turns)
|
|
277
|
-
- Type `exit` or `quit` to end session
|
|
278
|
-
- Cumulative statistics shown on exit
|
|
279
|
-
- Conversation log saved to `log.jsonl`
|
|
280
|
-
|
|
281
|
-
**Example session:**
|
|
282
|
-
```
|
|
283
|
-
$ coder -i
|
|
284
|
-
Interactive mode - working in: /path/to/dir
|
|
285
|
-
Type 'exit' or 'quit' to stop.
|
|
286
|
-
|
|
287
|
-
You: Load data.csv and show the columns
|
|
288
|
-
Agent working...
|
|
289
|
-
[Agent loads file, displays columns]
|
|
290
|
-
|
|
291
|
-
You: Plot the 'sales' column
|
|
292
|
-
Agent working...
|
|
293
|
-
[Agent creates plot using existing dataframe]
|
|
294
|
-
|
|
295
|
-
You: exit
|
|
296
|
-
Goodbye!
|
|
297
|
-
Log saved to: log.jsonl
|
|
298
|
-
```
|
|
308
|
+
When using the MCP server for domain-specific tasks (constraint programming, ASP, etc.), provide the project template content directly in your conversation. For example, paste the contents of `coder-examples/cpmpy/cpmpy.md` when working with CPMpy.
|
|
299
309
|
|
|
300
310
|
---
|
|
301
311
|
|
|
302
312
|
## Configuration
|
|
303
313
|
|
|
304
|
-
### API Key
|
|
314
|
+
### API Key (Coding Agent only)
|
|
305
315
|
|
|
306
|
-
The agent
|
|
316
|
+
The coding agent requires an OpenRouter API key. It looks in order:
|
|
307
317
|
1. `--api-key` flag or `api_key` parameter
|
|
308
318
|
2. `~/.config/coder/.env` file
|
|
309
319
|
3. `OPENROUTER_API_KEY` environment variable
|
|
310
320
|
|
|
311
321
|
```bash
|
|
312
|
-
# Recommended: one-time setup
|
|
313
322
|
mkdir -p ~/.config/coder
|
|
314
323
|
echo 'OPENROUTER_API_KEY="sk-or-v1-..."' > ~/.config/coder/.env
|
|
315
324
|
```
|
|
316
325
|
|
|
326
|
+
The MCP server does not require an API key — it only executes code.
|
|
327
|
+
|
|
317
328
|
### Environment Variables
|
|
318
329
|
|
|
319
330
|
| Variable | Description |
|
|
320
331
|
|----------|-------------|
|
|
321
|
-
| `OPENROUTER_API_KEY` | API key for OpenRouter |
|
|
332
|
+
| `OPENROUTER_API_KEY` | API key for OpenRouter (agent only) |
|
|
322
333
|
| `CODER_VERBOSE` | Show detailed model configuration |
|
|
323
|
-
| `CODER_WITH_PACKAGES` | Comma-separated packages (internal use) |
|
|
324
|
-
|
|
325
|
-
---
|
|
326
|
-
|
|
327
|
-
## How It Works
|
|
328
|
-
|
|
329
|
-
1. Task is parsed and sent to the LLM
|
|
330
|
-
2. Agent reasons about approach using ReAct framework
|
|
331
|
-
3. Code executes in persistent IPython kernel (state preserved)
|
|
332
|
-
4. Errors detected and fixed automatically
|
|
333
|
-
5. Solution refined until complete
|
|
334
|
-
|
|
335
|
-
### Output Files
|
|
336
|
-
|
|
337
|
-
- **Inline tasks**: `solution.py` + `log.jsonl`
|
|
338
|
-
- **File tasks**: `{basename}_code.py` + `{basename}.jsonl`
|
|
339
334
|
|
|
340
335
|
---
|
|
341
336
|
|
|
342
337
|
## Security Notice
|
|
343
338
|
|
|
344
|
-
**This is experimental software.**
|
|
339
|
+
**This is experimental software.** Both the coding agent and MCP server execute code automatically.
|
|
345
340
|
|
|
346
341
|
- Run in a VM or container for untrusted inputs
|
|
347
342
|
- Code executes in the working directory
|