agentic-python-coder 2.1.0__tar.gz → 2.2.1__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.
Files changed (65) hide show
  1. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/.gitignore +6 -4
  2. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/PKG-INFO +150 -162
  3. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/README.md +147 -161
  4. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/prompts/system.md +3 -15
  5. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/prompts/system_todo.md +10 -22
  6. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/__init__.py +1 -1
  7. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/agent.py +2 -3
  8. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1/coder/src/agentic_python_coder}/examples/cpmpy/cpmpy.md +3 -1
  9. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/kernel.py +20 -16
  10. agentic_python_coder-2.2.1/coder/src/agentic_python_coder/mcp_server.py +485 -0
  11. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/runner.py +1 -28
  12. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/tools.py +1 -44
  13. agentic_python_coder-2.2.1/coder/tests/test_kernel.py +193 -0
  14. agentic_python_coder-2.2.1/coder/tests/test_library_api.py +159 -0
  15. agentic_python_coder-2.2.1/coder/tests/test_mcp_server.py +327 -0
  16. agentic_python_coder-2.2.1/coder/tests/test_todo_flag_integration.py +128 -0
  17. agentic_python_coder-2.2.1/coder/tests/test_todo_tool_availability.py +51 -0
  18. agentic_python_coder-2.2.1/examples/regex/sample_tasks/test_email/email_extractor.py +77 -0
  19. agentic_python_coder-2.2.1/examples/regex/sample_tasks/test_email/extracted_emails.txt +7 -0
  20. agentic_python_coder-2.2.1/examples/regex/sample_tasks/test_email/text.txt +1 -0
  21. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/pyproject.toml +4 -1
  22. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/LICENSE +0 -0
  23. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/.gitignore +0 -0
  24. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/cli.py +0 -0
  25. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/__init__.py +0 -0
  26. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/clingo/README.md +0 -0
  27. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/clingo/clingo.md +0 -0
  28. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/bird_reasoning.md +0 -0
  29. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/diagnosis.md +0 -0
  30. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/simple_coloring.md +0 -0
  31. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/stable_marriage.md +0 -0
  32. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/clingo/sample_tasks/sudoku_mini.md +0 -0
  33. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/cpmpy/README.md +0 -0
  34. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/cpmpy/sample_tasks/magic_square.md +0 -0
  35. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/cpmpy/sample_tasks/n_queens.md +0 -0
  36. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/regex/README.md +0 -0
  37. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/regex/regex.md +0 -0
  38. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/regex/sample_tasks/email_extraction.md +0 -0
  39. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/regex/sample_tasks/phone_validation.md +0 -0
  40. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/examples/regex/sample_tasks/url_parsing.md +0 -0
  41. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/llm.py +0 -0
  42. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/models/deepseek31.json +0 -0
  43. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/models/gemini25.json +0 -0
  44. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/models/gpt5.json +0 -0
  45. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/models/grok41.json +0 -0
  46. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/models/opus45.json +0 -0
  47. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/models/qwen3.json +0 -0
  48. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/models/sonnet45.json +0 -0
  49. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/coder/src/agentic_python_coder/project_md.py +0 -0
  50. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/clingo/README.md +0 -0
  51. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/clingo/clingo.md +0 -0
  52. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/clingo/sample_tasks/bird_reasoning.md +0 -0
  53. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/clingo/sample_tasks/diagnosis.md +0 -0
  54. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/clingo/sample_tasks/simple_coloring.md +0 -0
  55. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/clingo/sample_tasks/stable_marriage.md +0 -0
  56. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/clingo/sample_tasks/sudoku_mini.md +0 -0
  57. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/cpmpy/README.md +0 -0
  58. {agentic_python_coder-2.1.0/coder/src/agentic_python_coder → agentic_python_coder-2.2.1}/examples/cpmpy/cpmpy.md +0 -0
  59. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/cpmpy/sample_problems/magic_square.md +0 -0
  60. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/cpmpy/sample_problems/n_queens.md +0 -0
  61. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/regex/README.md +0 -0
  62. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/regex/regex.md +0 -0
  63. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/regex/sample_tasks/email_extraction.md +0 -0
  64. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/regex/sample_tasks/phone_validation.md +0 -0
  65. {agentic_python_coder-2.1.0 → agentic_python_coder-2.2.1}/examples/regex/sample_tasks/url_parsing.md +0 -0
@@ -152,7 +152,9 @@ cython_debug/
152
152
  uv.lock
153
153
 
154
154
  # Project specific
155
+ coder-examples/
155
156
  CLAUDE-archive.md
157
+ PROCESS_NOTES.md
156
158
  conversation_log.json
157
159
  coder_output.log
158
160
  task.md
@@ -173,10 +175,10 @@ examples/cpmpy/cpmpy_v*.md
173
175
  examples/cpmpy/cpmpy.md.backup-*
174
176
  examples/clingo/clingo_v*.md
175
177
 
176
- # Test files and folders
177
- test-*/
178
- test_*.py
179
- test_*/
178
+ # Test files and folders (root level only)
179
+ /test-*/
180
+ /test_*.py
181
+ /test_*/
180
182
  PROBLEM.md
181
183
  *.log
182
184
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentic-python-coder
3
- Version: 2.1.0
3
+ Version: 2.2.1
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
  [![Python 3.13](https://img.shields.io/badge/python-3.13-blue.svg)](https://www.python.org/downloads/)
39
41
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
42
+ [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-green.svg)](https://modelcontextprotocol.io/)
40
43
  [![UV](https://img.shields.io/badge/Packaged%20with-UV-purple)](https://github.com/astral-sh/uv)
41
44
  [![LangGraph](https://img.shields.io/badge/Built%20with-LangGraph-green)](https://github.com/langchain-ai/langgraph)
42
45
 
43
- A Python coding agent using the ReAct framework with a persistent IPython kernel. Works as a **CLI tool** or as a **Python library** for integration into your own applications.
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
- ### CLI Installation
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
- ### Library Installation
73
+ Get your API key from [openrouter.ai](https://openrouter.ai).
67
74
 
68
- ```bash
69
- # Add to your project
70
- uv add agentic-python-coder
75
+ ### For the MCP Server
71
76
 
72
- # Or with pip
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
- API key options:
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
- ### CLI Usage
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
- # Task from file
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
- # Initialize example templates (one-time)
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
- # With packages and project template
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
@@ -106,7 +198,7 @@ messages, stats, log_path = coder.solve_task(
106
198
  "Write a fibonacci function",
107
199
  working_directory="/tmp/workspace",
108
200
  model="sonnet45",
109
- quiet=True, # Suppress console output
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
120
-
121
- ### `solve_task()` — High-Level API
209
+ ### Library API Reference
122
210
 
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
@@ -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
- ### `create_coding_agent()` / `run_agent()` — Low-Level API
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
@@ -166,189 +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
- ### `get_openrouter_llm()` — LLM Access
174
-
175
- Get a configured LangChain LLM instance for custom use.
258
+ #### `get_openrouter_llm()` — LLM Access
176
259
 
177
260
  ```python
178
261
  from agentic_python_coder import get_openrouter_llm, list_available_models
179
262
 
180
- # Get LLM by model name
181
263
  llm = get_openrouter_llm(model="sonnet45")
182
-
183
- # See available models
184
264
  print(list_available_models())
185
265
  # ['deepseek31', 'gemini25', 'gpt5', 'grok41', 'opus45', 'qwen3', 'sonnet45']
186
-
187
- # Use a custom model JSON file
188
- llm = get_openrouter_llm(model="./mymodel.json")
189
266
  ```
190
267
 
191
268
  ---
192
269
 
193
- ## CLI Reference
270
+ ## The MCP Server
194
271
 
195
- ### Basic Commands
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.
196
273
 
197
- ```bash
198
- # Inline task
199
- coder "your task"
274
+ ### MCP Server Configuration
200
275
 
201
- # Task from file (creates {basename}_code.py and {basename}.jsonl)
202
- coder --task problem.md
276
+ Add to your MCP settings (e.g., `~/.claude/claude_desktop_config.json` or project `.mcp.json`):
203
277
 
204
- # Specify working directory
205
- coder --dir results/test1 "your task"
206
-
207
- # Interactive mode
208
- coder -i
278
+ ```json
279
+ {
280
+ "mcpServers": {
281
+ "ipython": {
282
+ "command": "uvx",
283
+ "args": ["--from", "agentic-python-coder", "ipython_mcp"]
284
+ }
285
+ }
286
+ }
209
287
  ```
210
288
 
211
- ### Options
289
+ ### Available Tools
212
290
 
213
- | Flag | Description |
291
+ | Tool | Description |
214
292
  |------|-------------|
215
- | `--version`, `-V` | Show version and exit |
216
- | `--init [TEMPLATE]` | Initialize example templates (cpmpy, clingo, regex, or all) |
217
- | `--task`, `-t FILE` | Load task from markdown file |
218
- | `--model MODEL` | Model name or JSON file (default: sonnet45) |
219
- | `--project`, `-p FILE` | Project template for domain-specific prompts |
220
- | `--with PACKAGE` | Add packages dynamically (repeatable) |
221
- | `--dir`, `-d DIR` | Working directory |
222
- | `--api-key KEY` | Override API key |
223
- | `--todo` | Enable task tracking tool |
224
- | `--quiet`, `-q` | Suppress console output |
225
- | `--step-limit N` | Max agent steps (default: 200) |
226
- | `-i`, `--interactive` | Interactive conversation mode |
227
-
228
- ### Model Selection
229
-
230
- ```bash
231
- # Built-in models (versioned names)
232
- coder --model sonnet45 "task" # Claude Sonnet 4.5 (default)
233
- coder --model opus45 "task" # Claude Opus 4.5
234
- coder --model deepseek31 "task" # DeepSeek v3.1
235
- coder --model grok41 "task" # X.AI Grok 4.1
236
- coder --model qwen3 "task" # Qwen3 Coder
237
- coder --model gemini25 "task" # Gemini Pro 2.5
238
- coder --model gpt5 "task" # GPT-5
239
-
240
- # Custom model (JSON file)
241
- coder --model ./mymodel.json "task"
242
- ```
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. |
243
297
 
244
- ### Project Templates
298
+ ### Features
245
299
 
246
- Domain-specific templates improve results. First, initialize the examples:
247
-
248
- ```bash
249
- # Initialize all example templates (creates coder-examples/ directory)
250
- coder --init
251
-
252
- # Or initialize only specific templates
253
- coder --init cpmpy
254
- ```
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
255
305
 
256
- Then use them:
306
+ ### Usage Tips
257
307
 
258
- ```bash
259
- # Constraint programming
260
- coder --with cpmpy --project coder-examples/cpmpy/cpmpy.md "Solve 8-queens"
261
-
262
- # Run a sample task
263
- coder --with cpmpy --project coder-examples/cpmpy/cpmpy.md \
264
- --task coder-examples/cpmpy/sample_tasks/n_queens.md
265
-
266
- # Answer Set Programming
267
- coder --with clingo --project coder-examples/clingo/clingo.md "Model bird flight"
268
- ```
269
-
270
- ### Interactive Mode
271
-
272
- Interactive mode (`-i`) maintains a persistent session for multi-turn conversations:
273
-
274
- ```bash
275
- # Start interactive session
276
- coder -i
277
-
278
- # With project template
279
- coder -i --project coder-examples/cpmpy/cpmpy.md --with cpmpy
280
- ```
281
-
282
- **Features:**
283
- - Persistent IPython kernel (state preserved across turns)
284
- - Type `exit` or `quit` to end session
285
- - Cumulative statistics shown on exit
286
- - Conversation log saved to `log.jsonl`
287
-
288
- **Example session:**
289
- ```
290
- $ coder -i
291
- Interactive mode - working in: /path/to/dir
292
- Type 'exit' or 'quit' to stop.
293
-
294
- You: Load data.csv and show the columns
295
- Agent working...
296
- [Agent loads file, displays columns]
297
-
298
- You: Plot the 'sales' column
299
- Agent working...
300
- [Agent creates plot using existing dataframe]
301
-
302
- You: exit
303
- Goodbye!
304
- Log saved to: log.jsonl
305
- ```
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.
306
309
 
307
310
  ---
308
311
 
309
312
  ## Configuration
310
313
 
311
- ### API Key
314
+ ### API Key (Coding Agent only)
312
315
 
313
- The agent looks for API key in order:
316
+ The coding agent requires an OpenRouter API key. It looks in order:
314
317
  1. `--api-key` flag or `api_key` parameter
315
318
  2. `~/.config/coder/.env` file
316
319
  3. `OPENROUTER_API_KEY` environment variable
317
320
 
318
321
  ```bash
319
- # Recommended: one-time setup
320
322
  mkdir -p ~/.config/coder
321
323
  echo 'OPENROUTER_API_KEY="sk-or-v1-..."' > ~/.config/coder/.env
322
324
  ```
323
325
 
326
+ The MCP server does not require an API key — it only executes code.
327
+
324
328
  ### Environment Variables
325
329
 
326
330
  | Variable | Description |
327
331
  |----------|-------------|
328
- | `OPENROUTER_API_KEY` | API key for OpenRouter |
332
+ | `OPENROUTER_API_KEY` | API key for OpenRouter (agent only) |
329
333
  | `CODER_VERBOSE` | Show detailed model configuration |
330
- | `CODER_WITH_PACKAGES` | Comma-separated packages (internal use) |
331
-
332
- ---
333
-
334
- ## How It Works
335
-
336
- 1. Task is parsed and sent to the LLM
337
- 2. Agent reasons about approach using ReAct framework
338
- 3. Code executes in persistent IPython kernel (state preserved)
339
- 4. Errors detected and fixed automatically
340
- 5. Solution refined until complete
341
-
342
- ### Output Files
343
-
344
- - **Inline tasks**: `solution.py` + `log.jsonl`
345
- - **File tasks**: `{basename}_code.py` + `{basename}.jsonl`
346
334
 
347
335
  ---
348
336
 
349
337
  ## Security Notice
350
338
 
351
- **This is experimental software.** The agent executes code automatically.
339
+ **This is experimental software.** Both the coding agent and MCP server execute code automatically.
352
340
 
353
341
  - Run in a VM or container for untrusted inputs
354
342
  - Code executes in the working directory