smerkil 0.11.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 (51) hide show
  1. smerkil-0.11.1/PKG-INFO +334 -0
  2. smerkil-0.11.1/README.md +320 -0
  3. smerkil-0.11.1/pyproject.toml +25 -0
  4. smerkil-0.11.1/setup.cfg +4 -0
  5. smerkil-0.11.1/smerkil/__init__.py +7 -0
  6. smerkil-0.11.1/smerkil/__main__.py +7 -0
  7. smerkil-0.11.1/smerkil/agent.py +444 -0
  8. smerkil-0.11.1/smerkil/alerts.py +197 -0
  9. smerkil-0.11.1/smerkil/budget.py +64 -0
  10. smerkil-0.11.1/smerkil/cli.py +1468 -0
  11. smerkil-0.11.1/smerkil/compaction.py +231 -0
  12. smerkil-0.11.1/smerkil/config.py +184 -0
  13. smerkil-0.11.1/smerkil/confirm.py +173 -0
  14. smerkil-0.11.1/smerkil/evals.py +104 -0
  15. smerkil-0.11.1/smerkil/hooks.py +108 -0
  16. smerkil-0.11.1/smerkil/llm.py +327 -0
  17. smerkil-0.11.1/smerkil/mcp.py +210 -0
  18. smerkil-0.11.1/smerkil/memory.py +172 -0
  19. smerkil-0.11.1/smerkil/memory_tools.py +91 -0
  20. smerkil-0.11.1/smerkil/planning.py +96 -0
  21. smerkil-0.11.1/smerkil/providers.py +405 -0
  22. smerkil-0.11.1/smerkil/serve.py +304 -0
  23. smerkil-0.11.1/smerkil/setup.py +274 -0
  24. smerkil-0.11.1/smerkil/skills.py +88 -0
  25. smerkil-0.11.1/smerkil/todos.py +113 -0
  26. smerkil-0.11.1/smerkil/tools.py +703 -0
  27. smerkil-0.11.1/smerkil/tui.py +391 -0
  28. smerkil-0.11.1/smerkil/ui.py +883 -0
  29. smerkil-0.11.1/smerkil.egg-info/PKG-INFO +334 -0
  30. smerkil-0.11.1/smerkil.egg-info/SOURCES.txt +49 -0
  31. smerkil-0.11.1/smerkil.egg-info/dependency_links.txt +1 -0
  32. smerkil-0.11.1/smerkil.egg-info/entry_points.txt +2 -0
  33. smerkil-0.11.1/smerkil.egg-info/top_level.txt +1 -0
  34. smerkil-0.11.1/tests/test_alerts.py +194 -0
  35. smerkil-0.11.1/tests/test_budget.py +93 -0
  36. smerkil-0.11.1/tests/test_chat_roles.py +140 -0
  37. smerkil-0.11.1/tests/test_compaction.py +275 -0
  38. smerkil-0.11.1/tests/test_confirm_and_memory.py +176 -0
  39. smerkil-0.11.1/tests/test_failover.py +129 -0
  40. smerkil-0.11.1/tests/test_git_tools.py +103 -0
  41. smerkil-0.11.1/tests/test_live.py +173 -0
  42. smerkil-0.11.1/tests/test_login.py +160 -0
  43. smerkil-0.11.1/tests/test_memory_store.py +118 -0
  44. smerkil-0.11.1/tests/test_push.py +119 -0
  45. smerkil-0.11.1/tests/test_replay.py +146 -0
  46. smerkil-0.11.1/tests/test_report.py +121 -0
  47. smerkil-0.11.1/tests/test_serve.py +148 -0
  48. smerkil-0.11.1/tests/test_todos_mcp.py +200 -0
  49. smerkil-0.11.1/tests/test_tool_streaming.py +120 -0
  50. smerkil-0.11.1/tests/test_ui_setup.py +595 -0
  51. smerkil-0.11.1/tests/test_v05.py +189 -0
@@ -0,0 +1,334 @@
1
+ Metadata-Version: 2.4
2
+ Name: smerkil
3
+ Version: 0.11.1
4
+ Summary: SMERKIL Agent — a production harness for building, evaluating and operating autonomous AI agents.
5
+ Author: SMERKIL Technologies
6
+ License: Apache-2.0
7
+ Keywords: agents,ai,harness,llm,tool-loop
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+
15
+ # SMERKIL Agent
16
+
17
+ A production harness for building, evaluating and operating autonomous AI agents.
18
+ Zero dependencies — stdlib only. Model-agnostic (any OpenAI-compatible endpoint).
19
+
20
+ ## Install
21
+
22
+ **Linux / macOS / WSL**
23
+ ```bash
24
+ curl -fsSL https://smerkil-technologies.vercel.app/install.sh | bash
25
+ ```
26
+
27
+ **Windows (PowerShell)**
28
+ ```powershell
29
+ irm https://smerkil-technologies.vercel.app/install.ps1 | iex
30
+ ```
31
+
32
+ > In `cmd.exe` there is no `bash` of its own — `curl ... | bash` there runs your
33
+ > WSL/Git-Bash Linux, and the result lives inside that Linux, not in Windows.
34
+ > Use PowerShell for a native Windows install.
35
+
36
+ **Any platform, manual**
37
+ ```bash
38
+ pip install --user https://smerkil-technologies.vercel.app/smerkil-0.11.1.tar.gz
39
+ # or isolated: uv tool install <tarball> / pipx install <tarball>
40
+ ```
41
+ Requires Python 3.10+. The installers verify the tarball's sha256 first.
42
+
43
+ ```bash
44
+ # first run: pick a provider, paste your key, any base URL you like.
45
+ # the wizard probes the endpoint and sends one live message before it says "ok"
46
+ smerkil init
47
+
48
+ # ...or answer it all in one line (no prompts)
49
+ smerkil init work --base-url https://generativelanguage.googleapis.com/v1beta \
50
+ --model gemini-2.5-flash --key "$GEMINI_API_KEY"
51
+
52
+ # just run it — no arguments = the chat UI
53
+ smerkil
54
+
55
+ # scaffold an agent with a role preset
56
+ smerkil new my-agent --role coder # general|coder|researcher|reviewer|writer
57
+
58
+ # edit agent.yaml (model, tools, guardrails), export a key...
59
+ export SMERKIL_API_KEY=sk-...
60
+ export SMERKIL_BASE_URL=https://api.openai.com/v1 # or any compatible endpoint
61
+
62
+ # run it
63
+ smerkil run my-agent --goal "Summarize ./notes/ and write brief.md"
64
+
65
+ # interactive session — streaming text AND tool-call args, persistent history
66
+ smerkil chat my-agent
67
+
68
+ # expose the agent as an HTTP API
69
+ smerkil serve my-agent --token $SERVE_TOKEN
70
+
71
+ # check environment, key, model reachability, workspace health
72
+ smerkil doctor my-agent
73
+
74
+ # check behavior before you ship
75
+ smerkil eval my-agent
76
+
77
+ # replay any run
78
+ smerkil trace list
79
+ smerkil trace my-agent --show <run-id>
80
+ ```
81
+
82
+ ## Providers and base URLs
83
+
84
+ Any endpoint that speaks `POST {base_url}/chat/completions` works. `smerkil init`
85
+ writes both `base_url` and `api_key_env` into `agent.yaml`; you can also pass
86
+ `--base-url` / `--model` on the command line for a single run, or set
87
+ `SMERKIL_BASE_URL`.
88
+
89
+ | Provider | base_url | key env |
90
+ |---|---|---|
91
+ | Google AI Studio (Gemini) | `https://generativelanguage.googleapis.com/v1beta/openai` | `GEMINI_API_KEY` |
92
+ | OpenAI | `https://api.openai.com/v1` | `OPENAI_API_KEY` |
93
+ | OpenRouter | `https://openrouter.ai/api/v1` | `OPENROUTER_API_KEY` |
94
+ | DeepSeek | `https://api.deepseek.com/v1` | `DEEPSEEK_API_KEY` |
95
+ | Groq | `https://api.groq.com/openai/v1` | `GROQ_API_KEY` |
96
+ | Mistral | `https://api.mistral.ai/v1` | `MISTRAL_API_KEY` |
97
+ | Ollama (local) | `http://localhost:11434/v1` | — |
98
+ | anything else | your own URL | any name you pick |
99
+
100
+ A URL is normalised for you: a bare host gets `https://`, a trailing
101
+ `/chat/completions` is dropped, and `generativelanguage.googleapis.com`
102
+ gets the `/v1beta/openai` compatibility path appended. If `base_url` is missing
103
+ but `api_key_env` is a known provider key (`GEMINI_API_KEY`, `GROQ_API_KEY`, …),
104
+ the endpoint is inferred from the key — that is why a Google key no longer
105
+ fails against the OpenAI default.
106
+
107
+ Keys are stored in `~/.smerkil/credentials.env` (mode 0600) and never printed
108
+ back in full.
109
+
110
+ ## What's inside
111
+
112
+ - **Tool loop runtime** — deterministic loop, parallel tool execution (a thread pool runs all tool calls from one model turn concurrently, results appended in deterministic order), token & turn budgets, hard stop on runaway loops.
113
+ - **Multi-turn chat** — `Agent.run(goal, history=[...])` records user, assistant and tool turns incrementally; context compaction can never tear a session apart. `smerkil chat` is a streaming REPL (`/reset`, `/tokens`, `/exit`).
114
+ - **Role presets** — `--role coder|researcher|reviewer|writer|general` scaffolds a tuned system prompt and tool set (coder/reviewer get the shell).
115
+ - **HTTP API** — `smerkil serve` exposes the agent over a stdlib HTTP server: `POST /v1/chat` (multi-turn, per-session history + shared session budget), `GET /sessions`, `GET /health`, `GET /live`; optional bearer-token auth.
116
+ - **Live status** — `smerkil status` finds a running server via its heartbeat file (`~/.smerkil/serve.json`) and reports which sessions are actually executing right now; `--json` for scripting.
117
+ - **Usage report** — `smerkil report` aggregates every agent's on-disk traces into one document (runs, turns, tool calls, tokens, cost, stop reasons, top tools); `smerkil push` sends it to a dashboard, opt-in.
118
+ - **Subagents** — the `subagent` tool spawns isolated child agents with their own context and goal; the child's final answer returns as a tool result. Children cannot spawn further subagents (bounded depth).
119
+ - **Context compaction** — when the transcript exceeds a token budget, older messages are summarized (system prompt and recent window kept verbatim). Summarizers are pluggable (`smerkil.compaction.Summarizer` protocol); the default `TruncatingSummarizer` needs no model, `ModelSummarizer` uses the chat model when `SMERKIL_MODEL_SUMMARIZER=1`.
120
+ - **Streaming** — SSE streaming from any OpenAI-compatible endpoint over stdlib `http.client`: text deltas (`on_token`) and live tool-call argument fragments (`on_tool_delta`); automatic non-streaming fallback when the endpoint doesn't support SSE.
121
+ - **Sticky model failover** — `fallback_models` tried in order; once a fallback serves, later turns skip the dead primary. Each trace step records the model that actually answered.
122
+ - **Failover-aware budget** — cost priced per the model that actually served each turn; chat and serve sessions share one session budget (visible via `/tokens` or `GET /sessions`, enforced mid-session).
123
+ - **Retries & backoff** — exponential backoff with jitter on connection errors and 429/5xx, honoring `Retry-After`.
124
+ - **Structured planning** — `plan_add` / `plan_list` / `plan_update` tools backed by `workspace/plan.md` with `todo` / `in_progress` / `done` statuses.
125
+ - **Human-in-the-loop confirmations** — `confirm.yaml` flags tools (or arg regexes) that pause the run and ask the human; non-interactive runs fail closed
126
+ - **Durable memory** — `memory_save` / `memory_search` / `memory_forget` persist across sessions in `.smerkil/memory.jsonl`; recent notes are auto-injected into every run's system prompt
127
+ - **More tools** — `web_fetch` (stdlib, size/time-limited, text extraction), `python_exec` (snippet in a sandboxed subprocess with timeout), `git_status` / `git_log` / `git_diff` (read-only), `git_commit` / `git_branch` (write), plus the sandboxed file tools and opt-in whitelisted shell.
128
+ - **Memory & state** — per-agent working memory, durable notes (`memory.md`), carried across runs.
129
+ - **Evals** — scenario suites (`evals.yaml`) with grounded-expectation checks; non-zero exit on regression. Ships role-aware scenarios covering planning and parallel tool calls.
130
+ - **Traces** — every run saved as JSONL (`workspace/traces/runs.jsonl`) plus per-run JSON with metadata: run id, per-step serving model, timestamps, token totals, compaction count. Pretty-print with `smerkil trace <name> --show <id>`.
131
+
132
+ ## The terminal UI
133
+
134
+ `smerkil` with no arguments opens the chat UI: a banner with the active
135
+ endpoint/model/workspace, streamed answers, a rail for every tool call
136
+ (`⚙ name key=value` → `✓` or `✗ error`), a live status line after each turn
137
+ (model · tokens in/out · dollars · elapsed), and a spinner while the model is
138
+ thinking. Colour and box-drawing appear only on a TTY: pipe the output or pass
139
+ `--plain` and you get one flat header line plus plain text, no escapes.
140
+
141
+ ```
142
+ smerkil # chat UI on the default agent
143
+ smerkil init # provider / base URL / key / model wizard
144
+ smerkil doctor # does this URL+key+model actually answer?
145
+ smerkil --plain # monochrome, no box drawing
146
+ smerkil --base-url https://api.groq.com/openai/v1 --model llama-3.3-70b-versatile
147
+ ```
148
+
149
+ Inside the UI:
150
+
151
+ | command | what it does |
152
+ |---|---|
153
+ | `/help` | list commands |
154
+ | `/model [name]` | show or switch model (persisted to agent.yaml) |
155
+ | `/endpoint [url]` | show or change the base URL — any OpenAI-compatible one |
156
+ | `/setup` | re-run the provider wizard |
157
+ | `/tools` | tools this agent may call |
158
+ | `/tokens` | token + dollar usage for the session, with a budget bar |
159
+ | `/status` | endpoint, model, workspace, where the key came from |
160
+ | `/verbose` | toggle full tool results |
161
+ | `/clear` | forget the conversation, keep durable memory |
162
+ | `/exit` | leave |
163
+
164
+ ## CLI reference
165
+
166
+ | Command | Purpose |
167
+ |---|---|
168
+ | `smerkil new <name> [--role R]` | Scaffold an agent dir with a role preset |
169
+ | `smerkil run <name> --goal "..."` | Run one goal; exit 0 only on completed run |
170
+ | `smerkil chat <name>` | Streaming REPL: live text + tool args, session budget, `/reset`, `/tokens`, `/exit` |
171
+ | `smerkil serve <name>` | HTTP API: `POST /v1/chat`, `GET /sessions`, `GET /health`, `GET /live`; `--host`, `--port`, `--token` |
172
+ | `smerkil login` | sign in to a dashboard; stores the session token in `~/.smerkil/dashboard.json` (0600) |
173
+ | `smerkil status` | live status of a running server — active runs, sessions, budgets; `--url`, `--token`, `--json`, `--max-age` |
174
+ | `smerkil push` | upload `smerkil report --json` to a dashboard; `--url`, `--token-file` (opt-in) |
175
+ | `smerkil eval <name> [-v]` | Run eval scenarios; non-zero exit on regression |
176
+ | `smerkil trace <name> [--show <id>]` | List runs or pretty-print one trace |
177
+ | `smerkil doctor [name]` | Check API key env, endpoint/model reachability, workspace health |
178
+ | `smerkil --version` | Print version |
179
+
180
+ Output is ANSI-colored on TTYs, plain when piped.
181
+
182
+ ## HTTP API (`smerkil serve`)
183
+
184
+ ```bash
185
+ smerkil serve my-agent --host 127.0.0.1 --port 8317 --token "$SERVE_TOKEN"
186
+
187
+ # health
188
+ curl http://127.0.0.1:8317/health
189
+
190
+ # chat (multi-turn within a session id)
191
+ curl -X POST http://127.0.0.1:8317/v1/chat \
192
+ -H "Authorization: Bearer $SERVE_TOKEN" \
193
+ -H "Content-Type: application/json" \
194
+ -d '{"message": "Summarize ./notes/", "session": "job-42"}'
195
+
196
+ # per-session token/cost accounting
197
+ curl -H "Authorization: Bearer $SERVE_TOKEN" http://127.0.0.1:8317/sessions
198
+ ```
199
+
200
+ Each `session` id carries its own conversation history and session budget
201
+ (guardrails from `agent.yaml`); runs inside one session are serialized,
202
+ different sessions run concurrently.
203
+
204
+ ### Live status
205
+
206
+ `smerkil serve` writes a heartbeat to `$SMERKIL_HOME/serve.json` every 5s, so
207
+ `smerkil status` can find it without knowing the port:
208
+
209
+ ```bash
210
+ $ smerkil status
211
+ smerkil status stub · stub-1
212
+ pid 619248 · http://127.0.0.1:39567 · up since 2026-10-25T21:13:01+00:00
213
+ 1 running · 3 session(s)
214
+
215
+ ○ idle job-A runs 1 0p/0c $0.0 completed
216
+ ○ idle job-B runs 1 0p/0c $0.0 completed
217
+ ● running watch-me runs 0 0p/0c $0.0 —
218
+ ```
219
+
220
+ `GET /live` returns the same data as JSON: per-session `in_flight`, `runs`,
221
+ `last_stop_reason` and budget, plus server-wide `active_runs`. Exits non-zero
222
+ when nothing is serving, and `--json` is there for scripts:
223
+
224
+ ```bash
225
+ smerkil status --json | jq '.active_runs'
226
+ ```
227
+
228
+ A heartbeat older than `--max-age` (default 20s), or one whose pid is gone, is
229
+ treated as "not running" — a crashed server can't masquerade as live.
230
+
231
+ ### Seeing it from a hosted dashboard
232
+
233
+ Your machine is behind NAT; a hosted page can't open a socket to it. So the
234
+ direction is inverted — the harness pushes its status *up*, and the dashboard
235
+ just reads it:
236
+
237
+ ```bash
238
+ smerkil login --url https://smerkil-web.vercel.app # once, password not echoed
239
+ smerkil serve coder --publish-live # then every ~5s
240
+ ```
241
+
242
+ `POST /api/live` carries the same snapshot `GET /live` returns. A snapshot
243
+ older than 45s means the server stopped pushing, so the dashboard reports it
244
+ as offline rather than showing a stale "running". Everything is opt-in:
245
+ without `--publish-live` nothing leaves the machine. `smerkil push` and
246
+ `smerkil status` reuse the token from `login`, so it only has to be typed once.
247
+
248
+ ### Git workflow tools
249
+
250
+ The coder role ships with a full read/write git toolset — the agent can
251
+ inspect, stage, commit and branch without shell access:
252
+
253
+ ```yaml
254
+ tools: [git_status, git_log, git_diff, git_commit, git_branch]
255
+ ```
256
+
257
+ - `git_status` — porcelain status of the repo containing the workspace
258
+ - `git_log` — recent commits (`{max_count}`)
259
+ - `git_diff` — uncommitted worktree/staged diff, or `{commit: "HEAD~1"}` for a specific commit; untracked files are shown too
260
+ - `git_commit` — stage and commit in one call: `{message, add: ["."]} `; refuses to run with an empty message or nothing staged
261
+ - `git_branch` — `{action: list|create|switch, name}`; names are validated against git ref rules
262
+
263
+ Reviewer gets the read-only subset (`git_diff` included) — it can see exactly
264
+ what changed, but cannot mutate history.
265
+
266
+ ### Human-in-the-loop confirmations
267
+
268
+ Flag tools or argument patterns in `<workspace>/confirm.yaml`:
269
+
270
+ ```yaml
271
+ confirm:
272
+ tools:
273
+ - run_shell # always confirm shell commands
274
+ - git_commit
275
+ patterns: # confirm only matching args
276
+ - tool: web_fetch
277
+ match: "https?://internal\\."
278
+ ask_once_per_run: true # identical repeat calls re-use the approval
279
+ ```
280
+
281
+ The run pauses and prompts on the terminal: `⚠ confirm run_shell({...}) —
282
+ allow? [y/N/a]`. The decision is made by the human, not the model — it can't
283
+ be skipped, faked, or talked out of. Denial returns a structured error to the
284
+ LLM ("denied by human: do not retry"). Non-interactive environments (CI,
285
+ subagents) **fail closed**: the call is denied, not silently allowed.
286
+ Environment switches: `SMERKIL_CONFIRM=1` (all shell), `SMERKIL_CONFIRM_ALL=1`
287
+ (every tool). Inspect what the agent remembers with `smerkil memory <name>`.
288
+
289
+ ### Durable memory across sessions
290
+
291
+ The agent keeps notes in `<workspace>/.smerkil/memory.jsonl` (survives
292
+ restarts and reinstalls). Three tools, added automatically to every agent:
293
+
294
+ - `memory_save` — `{text, tags?}`: persist a self-contained fact (capped at 2000 chars)
295
+ - `memory_search` — `{query, limit?}`: keyword retrieval with tag weighting and a recency boost
296
+ - `memory_forget` — `{id}` or `{query}`: delete stale notes
297
+
298
+ The **8 most recent notes are auto-injected** into every run's system prompt
299
+ (char-capped), so context survives even if the model never calls
300
+ `memory_search`. Old-style `memory.md` keeps working alongside.
301
+
302
+ ## Configuration (agent.yaml)
303
+
304
+ ```yaml
305
+ name: my-agent
306
+ model: gpt-4o-mini
307
+ # tried in order when the primary fails definitively; once a fallback serves,
308
+ # later turns prefer it (sticky) until it too fails
309
+ fallback_models: [gpt-4o-mini, claude-haiku-4.5]
310
+ base_url: https://api.openai.com/v1 # any OpenAI-compatible endpoint
311
+ api_key_env: SMERKIL_API_KEY
312
+ system: You are my-agent. Plan, act with tools, verify, answer.
313
+ tools: [read_file, write_file, list_dir, memory_note,
314
+ plan_add, plan_list, plan_update,
315
+ python_exec, web_fetch, git_status, git_log, git_diff,
316
+ git_commit, git_branch, subagent]
317
+ guardrails:
318
+ max_turns: 40
319
+ budget:
320
+ tokens: 200000
321
+ usd: 1.00 # priced by the model that actually served each turn
322
+ sandbox: strict
323
+ allow_shell: false
324
+ ```
325
+
326
+ Existing 0.2.x `agent.yaml` and `evals.yaml` files work unchanged; new tools are opt-in via the `tools:` list (unknown tool names are skipped with a warning rather than crashing the run).
327
+
328
+ ## Available tools
329
+
330
+ `read_file`, `write_file`, `list_dir`, `run_shell` (whitelisted, opt-in), `memory_note`, `web_fetch`, `python_exec`, `git_status`, `git_log`, `git_diff`, `git_commit`, `git_branch`, `plan_add`, `plan_list`, `plan_update` (alias: `todo`), `grep`, `glob`, `checkpoint`, `subagent`.
331
+
332
+ MIT-grade boring infrastructure for probabilistic workers.
333
+
334
+ © 2026 SMERKIL Technologies
@@ -0,0 +1,320 @@
1
+ # SMERKIL Agent
2
+
3
+ A production harness for building, evaluating and operating autonomous AI agents.
4
+ Zero dependencies — stdlib only. Model-agnostic (any OpenAI-compatible endpoint).
5
+
6
+ ## Install
7
+
8
+ **Linux / macOS / WSL**
9
+ ```bash
10
+ curl -fsSL https://smerkil-technologies.vercel.app/install.sh | bash
11
+ ```
12
+
13
+ **Windows (PowerShell)**
14
+ ```powershell
15
+ irm https://smerkil-technologies.vercel.app/install.ps1 | iex
16
+ ```
17
+
18
+ > In `cmd.exe` there is no `bash` of its own — `curl ... | bash` there runs your
19
+ > WSL/Git-Bash Linux, and the result lives inside that Linux, not in Windows.
20
+ > Use PowerShell for a native Windows install.
21
+
22
+ **Any platform, manual**
23
+ ```bash
24
+ pip install --user https://smerkil-technologies.vercel.app/smerkil-0.11.1.tar.gz
25
+ # or isolated: uv tool install <tarball> / pipx install <tarball>
26
+ ```
27
+ Requires Python 3.10+. The installers verify the tarball's sha256 first.
28
+
29
+ ```bash
30
+ # first run: pick a provider, paste your key, any base URL you like.
31
+ # the wizard probes the endpoint and sends one live message before it says "ok"
32
+ smerkil init
33
+
34
+ # ...or answer it all in one line (no prompts)
35
+ smerkil init work --base-url https://generativelanguage.googleapis.com/v1beta \
36
+ --model gemini-2.5-flash --key "$GEMINI_API_KEY"
37
+
38
+ # just run it — no arguments = the chat UI
39
+ smerkil
40
+
41
+ # scaffold an agent with a role preset
42
+ smerkil new my-agent --role coder # general|coder|researcher|reviewer|writer
43
+
44
+ # edit agent.yaml (model, tools, guardrails), export a key...
45
+ export SMERKIL_API_KEY=sk-...
46
+ export SMERKIL_BASE_URL=https://api.openai.com/v1 # or any compatible endpoint
47
+
48
+ # run it
49
+ smerkil run my-agent --goal "Summarize ./notes/ and write brief.md"
50
+
51
+ # interactive session — streaming text AND tool-call args, persistent history
52
+ smerkil chat my-agent
53
+
54
+ # expose the agent as an HTTP API
55
+ smerkil serve my-agent --token $SERVE_TOKEN
56
+
57
+ # check environment, key, model reachability, workspace health
58
+ smerkil doctor my-agent
59
+
60
+ # check behavior before you ship
61
+ smerkil eval my-agent
62
+
63
+ # replay any run
64
+ smerkil trace list
65
+ smerkil trace my-agent --show <run-id>
66
+ ```
67
+
68
+ ## Providers and base URLs
69
+
70
+ Any endpoint that speaks `POST {base_url}/chat/completions` works. `smerkil init`
71
+ writes both `base_url` and `api_key_env` into `agent.yaml`; you can also pass
72
+ `--base-url` / `--model` on the command line for a single run, or set
73
+ `SMERKIL_BASE_URL`.
74
+
75
+ | Provider | base_url | key env |
76
+ |---|---|---|
77
+ | Google AI Studio (Gemini) | `https://generativelanguage.googleapis.com/v1beta/openai` | `GEMINI_API_KEY` |
78
+ | OpenAI | `https://api.openai.com/v1` | `OPENAI_API_KEY` |
79
+ | OpenRouter | `https://openrouter.ai/api/v1` | `OPENROUTER_API_KEY` |
80
+ | DeepSeek | `https://api.deepseek.com/v1` | `DEEPSEEK_API_KEY` |
81
+ | Groq | `https://api.groq.com/openai/v1` | `GROQ_API_KEY` |
82
+ | Mistral | `https://api.mistral.ai/v1` | `MISTRAL_API_KEY` |
83
+ | Ollama (local) | `http://localhost:11434/v1` | — |
84
+ | anything else | your own URL | any name you pick |
85
+
86
+ A URL is normalised for you: a bare host gets `https://`, a trailing
87
+ `/chat/completions` is dropped, and `generativelanguage.googleapis.com`
88
+ gets the `/v1beta/openai` compatibility path appended. If `base_url` is missing
89
+ but `api_key_env` is a known provider key (`GEMINI_API_KEY`, `GROQ_API_KEY`, …),
90
+ the endpoint is inferred from the key — that is why a Google key no longer
91
+ fails against the OpenAI default.
92
+
93
+ Keys are stored in `~/.smerkil/credentials.env` (mode 0600) and never printed
94
+ back in full.
95
+
96
+ ## What's inside
97
+
98
+ - **Tool loop runtime** — deterministic loop, parallel tool execution (a thread pool runs all tool calls from one model turn concurrently, results appended in deterministic order), token & turn budgets, hard stop on runaway loops.
99
+ - **Multi-turn chat** — `Agent.run(goal, history=[...])` records user, assistant and tool turns incrementally; context compaction can never tear a session apart. `smerkil chat` is a streaming REPL (`/reset`, `/tokens`, `/exit`).
100
+ - **Role presets** — `--role coder|researcher|reviewer|writer|general` scaffolds a tuned system prompt and tool set (coder/reviewer get the shell).
101
+ - **HTTP API** — `smerkil serve` exposes the agent over a stdlib HTTP server: `POST /v1/chat` (multi-turn, per-session history + shared session budget), `GET /sessions`, `GET /health`, `GET /live`; optional bearer-token auth.
102
+ - **Live status** — `smerkil status` finds a running server via its heartbeat file (`~/.smerkil/serve.json`) and reports which sessions are actually executing right now; `--json` for scripting.
103
+ - **Usage report** — `smerkil report` aggregates every agent's on-disk traces into one document (runs, turns, tool calls, tokens, cost, stop reasons, top tools); `smerkil push` sends it to a dashboard, opt-in.
104
+ - **Subagents** — the `subagent` tool spawns isolated child agents with their own context and goal; the child's final answer returns as a tool result. Children cannot spawn further subagents (bounded depth).
105
+ - **Context compaction** — when the transcript exceeds a token budget, older messages are summarized (system prompt and recent window kept verbatim). Summarizers are pluggable (`smerkil.compaction.Summarizer` protocol); the default `TruncatingSummarizer` needs no model, `ModelSummarizer` uses the chat model when `SMERKIL_MODEL_SUMMARIZER=1`.
106
+ - **Streaming** — SSE streaming from any OpenAI-compatible endpoint over stdlib `http.client`: text deltas (`on_token`) and live tool-call argument fragments (`on_tool_delta`); automatic non-streaming fallback when the endpoint doesn't support SSE.
107
+ - **Sticky model failover** — `fallback_models` tried in order; once a fallback serves, later turns skip the dead primary. Each trace step records the model that actually answered.
108
+ - **Failover-aware budget** — cost priced per the model that actually served each turn; chat and serve sessions share one session budget (visible via `/tokens` or `GET /sessions`, enforced mid-session).
109
+ - **Retries & backoff** — exponential backoff with jitter on connection errors and 429/5xx, honoring `Retry-After`.
110
+ - **Structured planning** — `plan_add` / `plan_list` / `plan_update` tools backed by `workspace/plan.md` with `todo` / `in_progress` / `done` statuses.
111
+ - **Human-in-the-loop confirmations** — `confirm.yaml` flags tools (or arg regexes) that pause the run and ask the human; non-interactive runs fail closed
112
+ - **Durable memory** — `memory_save` / `memory_search` / `memory_forget` persist across sessions in `.smerkil/memory.jsonl`; recent notes are auto-injected into every run's system prompt
113
+ - **More tools** — `web_fetch` (stdlib, size/time-limited, text extraction), `python_exec` (snippet in a sandboxed subprocess with timeout), `git_status` / `git_log` / `git_diff` (read-only), `git_commit` / `git_branch` (write), plus the sandboxed file tools and opt-in whitelisted shell.
114
+ - **Memory & state** — per-agent working memory, durable notes (`memory.md`), carried across runs.
115
+ - **Evals** — scenario suites (`evals.yaml`) with grounded-expectation checks; non-zero exit on regression. Ships role-aware scenarios covering planning and parallel tool calls.
116
+ - **Traces** — every run saved as JSONL (`workspace/traces/runs.jsonl`) plus per-run JSON with metadata: run id, per-step serving model, timestamps, token totals, compaction count. Pretty-print with `smerkil trace <name> --show <id>`.
117
+
118
+ ## The terminal UI
119
+
120
+ `smerkil` with no arguments opens the chat UI: a banner with the active
121
+ endpoint/model/workspace, streamed answers, a rail for every tool call
122
+ (`⚙ name key=value` → `✓` or `✗ error`), a live status line after each turn
123
+ (model · tokens in/out · dollars · elapsed), and a spinner while the model is
124
+ thinking. Colour and box-drawing appear only on a TTY: pipe the output or pass
125
+ `--plain` and you get one flat header line plus plain text, no escapes.
126
+
127
+ ```
128
+ smerkil # chat UI on the default agent
129
+ smerkil init # provider / base URL / key / model wizard
130
+ smerkil doctor # does this URL+key+model actually answer?
131
+ smerkil --plain # monochrome, no box drawing
132
+ smerkil --base-url https://api.groq.com/openai/v1 --model llama-3.3-70b-versatile
133
+ ```
134
+
135
+ Inside the UI:
136
+
137
+ | command | what it does |
138
+ |---|---|
139
+ | `/help` | list commands |
140
+ | `/model [name]` | show or switch model (persisted to agent.yaml) |
141
+ | `/endpoint [url]` | show or change the base URL — any OpenAI-compatible one |
142
+ | `/setup` | re-run the provider wizard |
143
+ | `/tools` | tools this agent may call |
144
+ | `/tokens` | token + dollar usage for the session, with a budget bar |
145
+ | `/status` | endpoint, model, workspace, where the key came from |
146
+ | `/verbose` | toggle full tool results |
147
+ | `/clear` | forget the conversation, keep durable memory |
148
+ | `/exit` | leave |
149
+
150
+ ## CLI reference
151
+
152
+ | Command | Purpose |
153
+ |---|---|
154
+ | `smerkil new <name> [--role R]` | Scaffold an agent dir with a role preset |
155
+ | `smerkil run <name> --goal "..."` | Run one goal; exit 0 only on completed run |
156
+ | `smerkil chat <name>` | Streaming REPL: live text + tool args, session budget, `/reset`, `/tokens`, `/exit` |
157
+ | `smerkil serve <name>` | HTTP API: `POST /v1/chat`, `GET /sessions`, `GET /health`, `GET /live`; `--host`, `--port`, `--token` |
158
+ | `smerkil login` | sign in to a dashboard; stores the session token in `~/.smerkil/dashboard.json` (0600) |
159
+ | `smerkil status` | live status of a running server — active runs, sessions, budgets; `--url`, `--token`, `--json`, `--max-age` |
160
+ | `smerkil push` | upload `smerkil report --json` to a dashboard; `--url`, `--token-file` (opt-in) |
161
+ | `smerkil eval <name> [-v]` | Run eval scenarios; non-zero exit on regression |
162
+ | `smerkil trace <name> [--show <id>]` | List runs or pretty-print one trace |
163
+ | `smerkil doctor [name]` | Check API key env, endpoint/model reachability, workspace health |
164
+ | `smerkil --version` | Print version |
165
+
166
+ Output is ANSI-colored on TTYs, plain when piped.
167
+
168
+ ## HTTP API (`smerkil serve`)
169
+
170
+ ```bash
171
+ smerkil serve my-agent --host 127.0.0.1 --port 8317 --token "$SERVE_TOKEN"
172
+
173
+ # health
174
+ curl http://127.0.0.1:8317/health
175
+
176
+ # chat (multi-turn within a session id)
177
+ curl -X POST http://127.0.0.1:8317/v1/chat \
178
+ -H "Authorization: Bearer $SERVE_TOKEN" \
179
+ -H "Content-Type: application/json" \
180
+ -d '{"message": "Summarize ./notes/", "session": "job-42"}'
181
+
182
+ # per-session token/cost accounting
183
+ curl -H "Authorization: Bearer $SERVE_TOKEN" http://127.0.0.1:8317/sessions
184
+ ```
185
+
186
+ Each `session` id carries its own conversation history and session budget
187
+ (guardrails from `agent.yaml`); runs inside one session are serialized,
188
+ different sessions run concurrently.
189
+
190
+ ### Live status
191
+
192
+ `smerkil serve` writes a heartbeat to `$SMERKIL_HOME/serve.json` every 5s, so
193
+ `smerkil status` can find it without knowing the port:
194
+
195
+ ```bash
196
+ $ smerkil status
197
+ smerkil status stub · stub-1
198
+ pid 619248 · http://127.0.0.1:39567 · up since 2026-10-25T21:13:01+00:00
199
+ 1 running · 3 session(s)
200
+
201
+ ○ idle job-A runs 1 0p/0c $0.0 completed
202
+ ○ idle job-B runs 1 0p/0c $0.0 completed
203
+ ● running watch-me runs 0 0p/0c $0.0 —
204
+ ```
205
+
206
+ `GET /live` returns the same data as JSON: per-session `in_flight`, `runs`,
207
+ `last_stop_reason` and budget, plus server-wide `active_runs`. Exits non-zero
208
+ when nothing is serving, and `--json` is there for scripts:
209
+
210
+ ```bash
211
+ smerkil status --json | jq '.active_runs'
212
+ ```
213
+
214
+ A heartbeat older than `--max-age` (default 20s), or one whose pid is gone, is
215
+ treated as "not running" — a crashed server can't masquerade as live.
216
+
217
+ ### Seeing it from a hosted dashboard
218
+
219
+ Your machine is behind NAT; a hosted page can't open a socket to it. So the
220
+ direction is inverted — the harness pushes its status *up*, and the dashboard
221
+ just reads it:
222
+
223
+ ```bash
224
+ smerkil login --url https://smerkil-web.vercel.app # once, password not echoed
225
+ smerkil serve coder --publish-live # then every ~5s
226
+ ```
227
+
228
+ `POST /api/live` carries the same snapshot `GET /live` returns. A snapshot
229
+ older than 45s means the server stopped pushing, so the dashboard reports it
230
+ as offline rather than showing a stale "running". Everything is opt-in:
231
+ without `--publish-live` nothing leaves the machine. `smerkil push` and
232
+ `smerkil status` reuse the token from `login`, so it only has to be typed once.
233
+
234
+ ### Git workflow tools
235
+
236
+ The coder role ships with a full read/write git toolset — the agent can
237
+ inspect, stage, commit and branch without shell access:
238
+
239
+ ```yaml
240
+ tools: [git_status, git_log, git_diff, git_commit, git_branch]
241
+ ```
242
+
243
+ - `git_status` — porcelain status of the repo containing the workspace
244
+ - `git_log` — recent commits (`{max_count}`)
245
+ - `git_diff` — uncommitted worktree/staged diff, or `{commit: "HEAD~1"}` for a specific commit; untracked files are shown too
246
+ - `git_commit` — stage and commit in one call: `{message, add: ["."]} `; refuses to run with an empty message or nothing staged
247
+ - `git_branch` — `{action: list|create|switch, name}`; names are validated against git ref rules
248
+
249
+ Reviewer gets the read-only subset (`git_diff` included) — it can see exactly
250
+ what changed, but cannot mutate history.
251
+
252
+ ### Human-in-the-loop confirmations
253
+
254
+ Flag tools or argument patterns in `<workspace>/confirm.yaml`:
255
+
256
+ ```yaml
257
+ confirm:
258
+ tools:
259
+ - run_shell # always confirm shell commands
260
+ - git_commit
261
+ patterns: # confirm only matching args
262
+ - tool: web_fetch
263
+ match: "https?://internal\\."
264
+ ask_once_per_run: true # identical repeat calls re-use the approval
265
+ ```
266
+
267
+ The run pauses and prompts on the terminal: `⚠ confirm run_shell({...}) —
268
+ allow? [y/N/a]`. The decision is made by the human, not the model — it can't
269
+ be skipped, faked, or talked out of. Denial returns a structured error to the
270
+ LLM ("denied by human: do not retry"). Non-interactive environments (CI,
271
+ subagents) **fail closed**: the call is denied, not silently allowed.
272
+ Environment switches: `SMERKIL_CONFIRM=1` (all shell), `SMERKIL_CONFIRM_ALL=1`
273
+ (every tool). Inspect what the agent remembers with `smerkil memory <name>`.
274
+
275
+ ### Durable memory across sessions
276
+
277
+ The agent keeps notes in `<workspace>/.smerkil/memory.jsonl` (survives
278
+ restarts and reinstalls). Three tools, added automatically to every agent:
279
+
280
+ - `memory_save` — `{text, tags?}`: persist a self-contained fact (capped at 2000 chars)
281
+ - `memory_search` — `{query, limit?}`: keyword retrieval with tag weighting and a recency boost
282
+ - `memory_forget` — `{id}` or `{query}`: delete stale notes
283
+
284
+ The **8 most recent notes are auto-injected** into every run's system prompt
285
+ (char-capped), so context survives even if the model never calls
286
+ `memory_search`. Old-style `memory.md` keeps working alongside.
287
+
288
+ ## Configuration (agent.yaml)
289
+
290
+ ```yaml
291
+ name: my-agent
292
+ model: gpt-4o-mini
293
+ # tried in order when the primary fails definitively; once a fallback serves,
294
+ # later turns prefer it (sticky) until it too fails
295
+ fallback_models: [gpt-4o-mini, claude-haiku-4.5]
296
+ base_url: https://api.openai.com/v1 # any OpenAI-compatible endpoint
297
+ api_key_env: SMERKIL_API_KEY
298
+ system: You are my-agent. Plan, act with tools, verify, answer.
299
+ tools: [read_file, write_file, list_dir, memory_note,
300
+ plan_add, plan_list, plan_update,
301
+ python_exec, web_fetch, git_status, git_log, git_diff,
302
+ git_commit, git_branch, subagent]
303
+ guardrails:
304
+ max_turns: 40
305
+ budget:
306
+ tokens: 200000
307
+ usd: 1.00 # priced by the model that actually served each turn
308
+ sandbox: strict
309
+ allow_shell: false
310
+ ```
311
+
312
+ Existing 0.2.x `agent.yaml` and `evals.yaml` files work unchanged; new tools are opt-in via the `tools:` list (unknown tool names are skipped with a warning rather than crashing the run).
313
+
314
+ ## Available tools
315
+
316
+ `read_file`, `write_file`, `list_dir`, `run_shell` (whitelisted, opt-in), `memory_note`, `web_fetch`, `python_exec`, `git_status`, `git_log`, `git_diff`, `git_commit`, `git_branch`, `plan_add`, `plan_list`, `plan_update` (alias: `todo`), `grep`, `glob`, `checkpoint`, `subagent`.
317
+
318
+ MIT-grade boring infrastructure for probabilistic workers.
319
+
320
+ © 2026 SMERKIL Technologies
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "smerkil"
7
+ version = "0.11.1"
8
+ description = "SMERKIL Agent — a production harness for building, evaluating and operating autonomous AI agents."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "SMERKIL Technologies" }]
13
+ keywords = ["agents", "ai", "harness", "llm", "tool-loop"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
19
+ ]
20
+
21
+ [project.scripts]
22
+ smerkil = "smerkil.cli:main"
23
+
24
+ [tool.setuptools.packages.find]
25
+ include = ["smerkil*"]