somnia 0.1.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.
Files changed (81) hide show
  1. somnia-0.1.0/LICENSE +21 -0
  2. somnia-0.1.0/PKG-INFO +580 -0
  3. somnia-0.1.0/README.md +555 -0
  4. somnia-0.1.0/openagent/__init__.py +5 -0
  5. somnia-0.1.0/openagent/__main__.py +10 -0
  6. somnia-0.1.0/openagent/cli/__init__.py +1 -0
  7. somnia-0.1.0/openagent/cli/commands.py +202 -0
  8. somnia-0.1.0/openagent/cli/main.py +103 -0
  9. somnia-0.1.0/openagent/cli/prompting.py +474 -0
  10. somnia-0.1.0/openagent/cli/repl.py +996 -0
  11. somnia-0.1.0/openagent/collaboration/__init__.py +1 -0
  12. somnia-0.1.0/openagent/collaboration/bus.py +40 -0
  13. somnia-0.1.0/openagent/collaboration/protocols.py +67 -0
  14. somnia-0.1.0/openagent/config/__init__.py +1 -0
  15. somnia-0.1.0/openagent/config/models.py +97 -0
  16. somnia-0.1.0/openagent/config/settings.py +417 -0
  17. somnia-0.1.0/openagent/mcp/__init__.py +1 -0
  18. somnia-0.1.0/openagent/mcp/client.py +67 -0
  19. somnia-0.1.0/openagent/mcp/registry.py +98 -0
  20. somnia-0.1.0/openagent/mcp/transport_http.py +138 -0
  21. somnia-0.1.0/openagent/mcp/transport_stdio.py +120 -0
  22. somnia-0.1.0/openagent/providers/__init__.py +1 -0
  23. somnia-0.1.0/openagent/providers/anthropic_provider.py +120 -0
  24. somnia-0.1.0/openagent/providers/base.py +53 -0
  25. somnia-0.1.0/openagent/providers/openai_provider.py +295 -0
  26. somnia-0.1.0/openagent/runtime/__init__.py +1 -0
  27. somnia-0.1.0/openagent/runtime/agent.py +826 -0
  28. somnia-0.1.0/openagent/runtime/compact.py +265 -0
  29. somnia-0.1.0/openagent/runtime/events.py +12 -0
  30. somnia-0.1.0/openagent/runtime/execution_mode.py +191 -0
  31. somnia-0.1.0/openagent/runtime/interrupts.py +5 -0
  32. somnia-0.1.0/openagent/runtime/messages.py +281 -0
  33. somnia-0.1.0/openagent/runtime/permissions.py +179 -0
  34. somnia-0.1.0/openagent/runtime/session.py +81 -0
  35. somnia-0.1.0/openagent/runtime/subagent_runner.py +159 -0
  36. somnia-0.1.0/openagent/runtime/system_prompt.py +99 -0
  37. somnia-0.1.0/openagent/runtime/teammate.py +615 -0
  38. somnia-0.1.0/openagent/runtime/tool_events.py +402 -0
  39. somnia-0.1.0/openagent/skills/__init__.py +1 -0
  40. somnia-0.1.0/openagent/skills/loader.py +114 -0
  41. somnia-0.1.0/openagent/storage/__init__.py +1 -0
  42. somnia-0.1.0/openagent/storage/common.py +58 -0
  43. somnia-0.1.0/openagent/storage/inbox.py +27 -0
  44. somnia-0.1.0/openagent/storage/jobs.py +39 -0
  45. somnia-0.1.0/openagent/storage/sessions.py +74 -0
  46. somnia-0.1.0/openagent/storage/tasks.py +172 -0
  47. somnia-0.1.0/openagent/storage/team.py +40 -0
  48. somnia-0.1.0/openagent/storage/tool_logs.py +62 -0
  49. somnia-0.1.0/openagent/storage/transcripts.py +34 -0
  50. somnia-0.1.0/openagent/tools/__init__.py +1 -0
  51. somnia-0.1.0/openagent/tools/background.py +113 -0
  52. somnia-0.1.0/openagent/tools/filesystem.py +428 -0
  53. somnia-0.1.0/openagent/tools/mcp.py +5 -0
  54. somnia-0.1.0/openagent/tools/process.py +75 -0
  55. somnia-0.1.0/openagent/tools/registry.py +48 -0
  56. somnia-0.1.0/openagent/tools/shell.py +118 -0
  57. somnia-0.1.0/openagent/tools/subagent.py +29 -0
  58. somnia-0.1.0/openagent/tools/tasks.py +129 -0
  59. somnia-0.1.0/openagent/tools/team.py +160 -0
  60. somnia-0.1.0/openagent/tools/todo.py +124 -0
  61. somnia-0.1.0/pyproject.toml +44 -0
  62. somnia-0.1.0/setup.cfg +4 -0
  63. somnia-0.1.0/somnia.egg-info/PKG-INFO +580 -0
  64. somnia-0.1.0/somnia.egg-info/SOURCES.txt +79 -0
  65. somnia-0.1.0/somnia.egg-info/dependency_links.txt +1 -0
  66. somnia-0.1.0/somnia.egg-info/entry_points.txt +2 -0
  67. somnia-0.1.0/somnia.egg-info/requires.txt +3 -0
  68. somnia-0.1.0/somnia.egg-info/top_level.txt +1 -0
  69. somnia-0.1.0/tests/test_cli_resume.py +229 -0
  70. somnia-0.1.0/tests/test_compact.py +163 -0
  71. somnia-0.1.0/tests/test_filesystem_tool.py +275 -0
  72. somnia-0.1.0/tests/test_markdown_rendering.py +87 -0
  73. somnia-0.1.0/tests/test_process_output.py +171 -0
  74. somnia-0.1.0/tests/test_prompting.py +75 -0
  75. somnia-0.1.0/tests/test_repl_todo.py +422 -0
  76. somnia-0.1.0/tests/test_runtime_tool_output.py +1060 -0
  77. somnia-0.1.0/tests/test_settings_overrides.py +267 -0
  78. somnia-0.1.0/tests/test_skill_loader.py +51 -0
  79. somnia-0.1.0/tests/test_subagent_tool.py +126 -0
  80. somnia-0.1.0/tests/test_teammate_runtime.py +536 -0
  81. somnia-0.1.0/tests/test_utils.py +95 -0
somnia-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OpenAgent Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
somnia-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,580 @@
1
+ Metadata-Version: 2.4
2
+ Name: somnia
3
+ Version: 0.1.0
4
+ Summary: A modular AI agent CLI inspired by the full reference harness.
5
+ Author: OpenAgent Team
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/your-org/openagent
8
+ Project-URL: Repository, https://github.com/your-org/openagent
9
+ Project-URL: Issues, https://github.com/your-org/openagent/issues
10
+ Keywords: ai,agent,cli,llm
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: anthropic>=0.25.0
22
+ Requires-Dist: prompt_toolkit>=3.0.43
23
+ Requires-Dist: tiktoken>=0.8.0
24
+ Dynamic: license-file
25
+
26
+ # Somnia (OpenAgent)
27
+
28
+ Somnia 是一个模块化的 AI Agent CLI 工具。名字来源于拉丁语"梦"(somnia),寓意用 AI 编织梦想。
29
+
30
+ > 内部模块仍使用 `openagent` 作为 Python 包名,`somnia` 是发布到 PyPI / npm 的产品名。
31
+
32
+ ## Prerequisites
33
+
34
+ | 方式 | 需要的环境 |
35
+ |------|-----------|
36
+ | `pip install` | **Python 3.11+**(自带 pip) |
37
+ | `npx somnia` | **Node.js 16+** + **Python 3.11+** |
38
+ | 一键脚本 | **curl / PowerShell**(脚本会检测并引导安装 Python) |
39
+ | Docker | **Docker**(什么都不用装) |
40
+
41
+ > 💡 如果你还没有 Python,去 [python.org](https://www.python.org/downloads/) 下载安装,
42
+ > 或用包管理器:`brew install python@3.12` / `winget install Python.Python.3.12`
43
+
44
+ ## Installation
45
+
46
+ ### 方式一:pip install(推荐)
47
+
48
+ ```bash
49
+ pip install somnia
50
+ ```
51
+
52
+ 安装后直接使用:
53
+
54
+ ```bash
55
+ somnia # 交互式 REPL
56
+ somnia chat "hi" # 单次对话
57
+ somnia doctor # 检查环境
58
+ ```
59
+
60
+ ### 方式二:一键安装脚本(自动检测 Python)
61
+
62
+ macOS / Linux:
63
+
64
+ ```bash
65
+ curl -fsSL https://raw.githubusercontent.com/your-org/openagent/main/scripts/install.sh | bash
66
+ ```
67
+
68
+ Windows PowerShell:
69
+
70
+ ```powershell
71
+ irm https://raw.githubusercontent.com/your-org/openagent/main/scripts/install.ps1 | iex
72
+ ```
73
+
74
+ > 脚本会自动检测 Python 3.11+,没有的话会提示你如何安装。
75
+
76
+ ### 方式三:npx(需要 Node.js + Python)
77
+
78
+ ```bash
79
+ npx somnia # 直接运行,首次会自动 pip install
80
+ npm install -g somnia # 或全局安装
81
+ ```
82
+
83
+ ### 方式四:Docker(零依赖,什么都不用装)
84
+
85
+ ```bash
86
+ docker build -t somnia .
87
+ docker run -it somnia # 交互式
88
+ docker run -it somnia chat "hello" # 单次对话
89
+ ```
90
+
91
+ ### 从源码安装(开发者)
92
+
93
+ ```bash
94
+ git clone https://github.com/your-org/openagent.git
95
+ cd openagent
96
+ pip install -e .
97
+ ```
98
+
99
+ ## Included in this MVP
100
+
101
+ - Interactive CLI with chat, run, tasks, compact, and doctor flows
102
+ - Single-agent loop with tool dispatch
103
+ - Filesystem and shell tools with workspace boundaries
104
+ - Session-scoped `TodoWrite`
105
+ - Persistent task graph
106
+ - Isolated subagent execution
107
+ - Skill loading from `skills/**/SKILL.md`
108
+ - Context micro-compact and transcript-backed auto-compact
109
+ - Background shell jobs with notifications
110
+ - Message bus, inbox, teammate runtime, shutdown requests, and plan approvals
111
+ - Anthropic provider and OpenAI-compatible provider adapters
112
+ - MCP client integration over `stdio` and HTTP
113
+ - Persistent sessions, transcripts, inbox, team state, and jobs under `.openagent/`
114
+
115
+ ## Coordination Flow
116
+
117
+ `subagent` is a disposable isolated worker, `task_*` is the persistent task system, and `team` tools manage long-lived teammates. They can be used independently, but the common collaboration flow looks like this:
118
+
119
+ ```mermaid
120
+ sequenceDiagram
121
+ autonumber
122
+ actor User
123
+ participant Lead as Lead Agent
124
+ participant Todo as Session TodoWrite
125
+ participant Sub as subagent tool
126
+ participant Child as Isolated Subagent
127
+ participant Tasks as TaskStore(task_*)
128
+ participant Team as TeammateRuntimeManager
129
+ participant Bus as MessageBus
130
+ participant Mate as Teammate
131
+
132
+ User->>Lead: Ask for a larger coding task
133
+ Lead->>Todo: TodoWrite(short checklist for this session)
134
+ Todo-->>Lead: Session-scoped progress
135
+
136
+ alt Lead wants a one-off isolated subtask
137
+ Lead->>Sub: subagent(prompt, agent_type)
138
+ Sub->>Child: run_subagent() with fresh messages
139
+ Child-->>Sub: concise summary only
140
+ Sub-->>Lead: tool_result(summary)
141
+ end
142
+
143
+ alt Lead wants persistent tracked work
144
+ Lead->>Tasks: task_create(subject, description)
145
+ Tasks-->>Lead: task id and pending state
146
+ end
147
+
148
+ alt Lead wants long-lived parallel help
149
+ Lead->>Team: spawn_teammate(name, role, prompt)
150
+ Team->>Mate: start worker loop
151
+ Mate->>Bus: read_inbox()
152
+ opt Teammate receives direct instruction
153
+ Lead->>Bus: send_message(to=teammate)
154
+ Bus-->>Mate: inbox message
155
+ end
156
+ opt Teammate picks up persistent work
157
+ Mate->>Tasks: list_claimable()/claim_task()
158
+ Tasks-->>Mate: claimed task
159
+ end
160
+ Mate-->>Bus: send_message(to=lead, progress/plan/result)
161
+ Bus-->>Lead: inbox message
162
+ end
163
+
164
+ Note over Lead,Todo: TodoWrite is only for the current session.
165
+ Note over Tasks,Team: task_* persists across turns and can be claimed by teammates.
166
+ Note over Sub,Child: subagent does not own persistent tasks and does not become a teammate.
167
+ ```
168
+
169
+ ## Subagent vs Teammate
170
+
171
+ Both `subagent` and teammates run with their own message history instead of sharing the lead session directly, but they are not equivalent workers.
172
+
173
+ | Aspect | `subagent` | Teammate (`spawn_teammate`) |
174
+ |---|---|---|
175
+ | Lifetime | Disposable, one call only | Long-lived worker loop |
176
+ | Message context | Fresh isolated `messages` per invocation | Persistent worker-local `messages` across work and idle cycles |
177
+ | Entry point | `subagent(prompt, agent_type)` | `spawn_teammate(name, role, prompt)` |
178
+ | Returns to lead | One summary string as tool result | Ongoing inbox messages, plan requests, and progress updates |
179
+ | Base role | One-off isolated helper | Persistent collaborator |
180
+ | Shell tool | Yes | Yes |
181
+ | File read | Yes | Yes |
182
+ | File write/edit | Only when `agent_type != "Explore"` | Yes |
183
+ | `TodoWrite` | No | No |
184
+ | Persistent `task_*` tools | No | Yes |
185
+ | Inbox / messaging tools | No | Yes |
186
+ | Can auto-claim persistent tasks | No | Yes |
187
+ | Can spawn more teammates | No | No |
188
+ | Can recursively spawn subagents | No | No |
189
+
190
+ Current tool boundaries in this repo:
191
+
192
+ - `subagent` gets `bash`, `read_file`, `load_skill`, and optionally `write_file` / `edit_file` for non-`Explore` runs.
193
+ - Teammates get `bash`, filesystem tools, `task_create`, `task_get`, `task_update`, `task_list`, `claim_task`, plus worker-local collaboration tools such as `send_message`, `idle`, and `submit_plan`.
194
+ - The lead agent has the broader coordination surface: `subagent`, `task_*`, team tools, `TodoWrite`, approvals, and other top-level runtime tools.
195
+
196
+ Practical rule:
197
+
198
+ - Use `subagent` when you want a clean one-off investigation or implementation pass and only need a summary back.
199
+ - Use a teammate when you want a persistent collaborator that can own tracked work, send updates, and resume later.
200
+
201
+ ## Agent Team
202
+
203
+ Agent Team is the long-lived collaboration layer in OpenAgent. Unlike `subagent`, which is a disposable isolated helper, a teammate is a named worker managed by `TeammateRuntimeManager` and coordinated through the message bus and persistent task system.
204
+
205
+ ### What a Teammate Is
206
+
207
+ - A teammate is created with `spawn_teammate(name, role, prompt)`.
208
+ - Each teammate runs in its own worker thread with its own message history.
209
+ - Teammates do not share the lead session transcript directly.
210
+ - Teammates are intended for ongoing collaboration, not one-off isolated delegation.
211
+
212
+ ### Lifecycle
213
+
214
+ The usual status flow is:
215
+
216
+ 1. `starting`
217
+ 2. `working`
218
+ 3. `idle`
219
+ 4. back to `working` when resumed by inbox messages or claimable tasks
220
+ 5. `shutdown` when the worker exits
221
+
222
+ Teammates stop running in these cases:
223
+
224
+ - The lead sends a `shutdown_request`.
225
+ - The teammate stays idle longer than `teammate_idle_timeout_seconds` without new inbox work or claimable tasks.
226
+ - The worker loop crashes with a runtime error.
227
+ - The OpenAgent process restarts. On the next boot, previously active teammates are repaired to `shutdown` with reason `runtime_restarted`.
228
+
229
+ ### What Persists
230
+
231
+ Teammates are workspace-scoped rather than session-scoped.
232
+
233
+ - Team member metadata is persisted under `.openagent/team/team.json`.
234
+ - Inbox messages are persisted under `.openagent/inbox/*.jsonl`.
235
+ - Persistent tasks used by teammates live under `.openagent/tasks/`.
236
+ - Shutdown and plan-approval workflow state lives under `.openagent/requests/`.
237
+
238
+ Persisted teammate metadata includes:
239
+
240
+ - `name`
241
+ - `role`
242
+ - `status`
243
+ - `activity`
244
+ - `last_transition_at`
245
+ - `last_activity_at`
246
+ - `shutdown_reason`
247
+ - `current_task_id`
248
+ - `last_error`
249
+
250
+ What does not persist:
251
+
252
+ - The worker thread itself
253
+ - The full teammate `messages` history
254
+ - In-memory reasoning state inside the worker loop
255
+
256
+ This means a teammate identity and status survive as project data, but an active worker must be spawned again after shutdown or process restart.
257
+
258
+ ### Tool Surface
259
+
260
+ Teammates have a narrower tool surface than the lead and a different one than `subagent`.
261
+
262
+ - Teammates can use shell and filesystem tools.
263
+ - Teammates can use persistent `task_*` tools and `claim_task`.
264
+ - Teammates can use worker-local collaboration tools such as `send_message`, `idle`, and `submit_plan`.
265
+ - Teammates cannot call `TodoWrite`.
266
+ - Teammates cannot spawn more teammates.
267
+ - Teammates cannot spawn `subagent`.
268
+
269
+ ### When to Use Agent Team
270
+
271
+ Use teammates when you need:
272
+
273
+ - A named worker that can keep collaborating over time
274
+ - Progress updates through inbox messages
275
+ - Ownership of persistent tracked work
276
+ - Automatic pickup of claimable tasks while idle
277
+
278
+ Do not use teammates when you only need:
279
+
280
+ - A single isolated research pass
281
+ - A one-off implementation summary
282
+ - A clean temporary context with no persistent ownership
283
+
284
+ That is the case where `subagent` is the better fit.
285
+
286
+ ## Layout
287
+
288
+ ```text
289
+ OpenAgent/
290
+ pyproject.toml
291
+ README.md
292
+ openagent.toml.example
293
+ openagent/
294
+ cli/
295
+ collaboration/
296
+ config/
297
+ mcp/
298
+ providers/
299
+ runtime/
300
+ skills/
301
+ storage/
302
+ tools/
303
+ ```
304
+
305
+ ## Quick Start
306
+
307
+ 1. Install the package in editable mode:
308
+
309
+ ```bash
310
+ python -m pip install -e ./OpenAgent
311
+ ```
312
+
313
+ 2. Copy the config file:
314
+
315
+ ```bash
316
+ mkdir -p .openagent
317
+ cp OpenAgent/openagent.toml.example .openagent/openagent.toml
318
+ ```
319
+
320
+ 3. Run a doctor check:
321
+
322
+ ```bash
323
+ python -m openagent doctor
324
+ ```
325
+
326
+ 4. Start interactive chat:
327
+
328
+ ```bash
329
+ python -m openagent
330
+ ```
331
+
332
+ You can also resume a previous session through the picker:
333
+
334
+ ```bash
335
+ python -m openagent -r
336
+ ```
337
+
338
+ You can override the provider or model for a single run without editing config files:
339
+
340
+ ```bash
341
+ python -m openagent --provider anthropic --model glm-5
342
+ python -m openagent --provider openai --model gpt-4.1
343
+ python -m openagent run --provider openai --model gpt-4.1 "Summarize this repo"
344
+ ```
345
+
346
+ If you install the console entrypoint, the same commands work as:
347
+
348
+ ```bash
349
+ openagent
350
+ openagent -r
351
+ ```
352
+
353
+ ## Configuration
354
+
355
+ OpenAgent reads configuration from:
356
+
357
+ 1. Global config at `~/.openagent/openagent.toml`
358
+ 2. Workspace config at `.openagent/openagent.toml`
359
+
360
+ For ad-hoc switching, command-line `--provider` and `--model` overrides take precedence for the current invocation only.
361
+
362
+ Both config files are optional. OpenAgent deep-merges them at runtime, and workspace settings override global settings when the same key is defined.
363
+
364
+ ### openagent.toml
365
+
366
+ Supported top-level sections:
367
+
368
+ - `[agent]`
369
+ - `[providers]`
370
+ - `[providers.<name>]`
371
+ - `[runtime]`
372
+ - `[[mcp_servers]]` or `[mcp_servers.<name>]`
373
+
374
+ Example:
375
+
376
+ ```toml
377
+ [agent]
378
+ name = "OpenAgent"
379
+ # Optional: fully override the built-in base system prompt.
380
+ # system_prompt = """
381
+ # You are a careful coding agent.
382
+ # """
383
+
384
+ [providers]
385
+ default = "anthropic"
386
+
387
+ [providers.anthropic]
388
+ models = ["claude-sonnet-4-5", "claude-3-5-haiku-latest"]
389
+ default_model = "claude-sonnet-4-5"
390
+ api_key = "replace-me"
391
+ # base_url = "https://api.anthropic.com"
392
+ # max_tokens = 8000
393
+ # timeout_seconds = 120
394
+
395
+ [providers.openai]
396
+ models = ["gpt-4.1", "gpt-4.1-mini"]
397
+ default_model = "gpt-4.1"
398
+ api_key = "replace-me"
399
+ # base_url = "https://api.openai.com/v1"
400
+ # organization = "org_xxx"
401
+ # max_tokens = 8000
402
+ # timeout_seconds = 120
403
+
404
+ [model_traits."claude-sonnet-4-5"]
405
+ cwt = 200000
406
+
407
+ [model_traits."claude-3-5-haiku-latest"]
408
+ cwt = 200000
409
+
410
+ [model_traits."gpt-4.1"]
411
+ cwt = 1047576
412
+
413
+ [model_traits."gpt-4.1-mini"]
414
+ cwt = 1047576
415
+
416
+ # Provider-specific override when needed.
417
+ #[model_traits.openrouter."gpt-4.1"]
418
+ #cwt = 262144
419
+
420
+ [runtime]
421
+ token_threshold = 100000
422
+ command_timeout_seconds = 120
423
+ background_poll_interval_seconds = 2
424
+ teammate_idle_timeout_seconds = 60
425
+ teammate_poll_interval_seconds = 5
426
+ max_tool_output_chars = 50000
427
+ max_subagent_rounds = 30
428
+ max_agent_rounds = 50
429
+
430
+ [[mcp_servers]]
431
+ name = "filesystem"
432
+ transport = "stdio"
433
+ command = "python"
434
+ args = ["server.py"]
435
+ cwd = "D:/tools/mcp-filesystem"
436
+ enabled = false
437
+ timeout_seconds = 30
438
+ protocol_version = "2025-11-25"
439
+
440
+ [mcp_servers.unityMCP]
441
+ transport = "http"
442
+ url = "http://127.0.0.1:8081/mcp"
443
+ http_headers = { "X-API-Key" = "replace-me", "Accept" = "text/event-stream" }
444
+ startup_timeout_sec = 20
445
+ enabled = false
446
+ ```
447
+
448
+ OpenAgent now uses provider-aware token counting for context tracking:
449
+
450
+ - Anthropic profiles prefer the native `messages.count_tokens` API.
451
+ - OpenAI-compatible profiles prefer `tiktoken`.
452
+ - The REPL status area shows current context usage as `used / total` plus percentage.
453
+ - Configure model-wide defaults under `model_traits."<model-id>"`.
454
+ - If the same model id needs a provider-specific override, use `model_traits.<provider>."<model-id>"`.
455
+ - Today the only model trait is `cwt`, which means `context_window_tokens`.
456
+
457
+ ### Selecting a Model
458
+
459
+ There are now three ways to choose the active model:
460
+
461
+ 1. Configure multiple models under `[providers.<name>]` in `openagent.toml`.
462
+ 2. Use `/model` inside the REPL to interactively switch provider and model.
463
+ 3. Pass `--provider` and `--model` on the command line for a one-off override.
464
+
465
+ Examples:
466
+
467
+ ```bash
468
+ openagent --provider anthropic --model glm-5
469
+ openagent chat --provider anthropic --model claude-sonnet-4-5
470
+ openagent run --provider openai --model gpt-4.1 "Explain the failing tests"
471
+ openagent doctor --provider openai --model gpt-4.1
472
+ ```
473
+
474
+ Inside the REPL, run:
475
+
476
+ ```text
477
+ /model
478
+ ```
479
+
480
+ OpenAgent will first show a provider picker, then a model picker limited to the models configured under that provider.
481
+
482
+ ### Agent Prompt Configuration
483
+
484
+ If you set only `agent.name`, OpenAgent uses the built-in default base prompt and injects the configured name into it.
485
+
486
+ ```toml
487
+ [agent]
488
+ name = "MyAgent"
489
+ ```
490
+
491
+ If you set `agent.system_prompt`, that string replaces the built-in base prompt.
492
+
493
+ ```toml
494
+ [agent]
495
+ name = "CodeReviewer"
496
+ system_prompt = """
497
+ You are a code review specialist.
498
+ Prioritize correctness, regressions, and missing tests.
499
+ """
500
+ ```
501
+
502
+ At runtime, OpenAgent also appends role-specific guidance to the base prompt, including:
503
+
504
+ - current workspace path
505
+ - available skills
506
+ - tool usage guidance
507
+ - current execution environment
508
+
509
+ The execution environment block tells the model which OS it is running on and how to use the `bash` tool correctly:
510
+
511
+ - on Unix-like systems, `bash` uses the system shell
512
+ - on Windows, `bash` runs PowerShell-compatible commands
513
+
514
+ That means Windows sessions should prefer commands such as:
515
+
516
+ - `Get-ChildItem`
517
+ - `Get-Content`
518
+ - `Select-String`
519
+ - `Select-Object`
520
+
521
+ ### MCP Server Configuration
522
+
523
+ OpenAgent supports both styles below.
524
+
525
+ Array style:
526
+
527
+ ```toml
528
+ [[mcp_servers]]
529
+ name = "filesystem"
530
+ transport = "stdio"
531
+ command = "python"
532
+ args = ["server.py"]
533
+ cwd = "D:/tools/mcp-filesystem"
534
+ enabled = true
535
+ ```
536
+
537
+ Named table style:
538
+
539
+ ```toml
540
+ [mcp_servers.unityMCP]
541
+ transport = "http"
542
+ url = "http://127.0.0.1:8081/mcp"
543
+ http_headers = { "X-API-Key" = "replace-me", "Accept" = "text/event-stream" }
544
+ startup_timeout_sec = 20
545
+ enabled = true
546
+ ```
547
+
548
+ Supported MCP fields include:
549
+
550
+ - `transport`
551
+ - `url`
552
+ - `command`
553
+ - `args`
554
+ - `cwd`
555
+ - `env`
556
+ - `http_headers`
557
+ - `enabled`
558
+ - `timeout_seconds` or `request_timeout_sec`
559
+ - `startup_timeout_sec`
560
+ - `protocol_version`
561
+
562
+ ## REPL Commands
563
+
564
+ - `/compact`
565
+ - `/model`
566
+ - `/tasks`
567
+ - `/team`
568
+ - `/inbox`
569
+ - `/mcp`
570
+ - `/toollog`
571
+ - `/bg`
572
+ - `/help`
573
+ - `/exit`
574
+
575
+ ## Notes
576
+
577
+ - Data is stored under `.openagent/` in the workspace root.
578
+ - MCP tools are exposed with the local name format `mcp__<server>__<tool>`.
579
+ - MCP config supports both `[[mcp_servers]]` array style and `[mcp_servers.<name>]` table style.
580
+ - The OpenAI adapter uses the chat completions API shape so provider differences stay isolated in `providers/`.