mandri 0.1.0a1__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.
- mandri-0.1.0a1/.gitignore +55 -0
- mandri-0.1.0a1/LICENSE +202 -0
- mandri-0.1.0a1/PKG-INFO +74 -0
- mandri-0.1.0a1/README.md +46 -0
- mandri-0.1.0a1/mandri/__init__.py +0 -0
- mandri-0.1.0a1/mandri/adapters/__init__.py +0 -0
- mandri-0.1.0a1/mandri/adapters/approval/__init__.py +9 -0
- mandri-0.1.0a1/mandri/adapters/approval/autopilot.py +150 -0
- mandri-0.1.0a1/mandri/adapters/approval/batcher.py +54 -0
- mandri-0.1.0a1/mandri/adapters/approval/manual.py +19 -0
- mandri-0.1.0a1/mandri/adapters/approval/yolo.py +9 -0
- mandri-0.1.0a1/mandri/adapters/config/__init__.py +3 -0
- mandri-0.1.0a1/mandri/adapters/config/toml/__init__.py +39 -0
- mandri-0.1.0a1/mandri/adapters/config/toml/decode.py +195 -0
- mandri-0.1.0a1/mandri/adapters/config/toml/encode.py +95 -0
- mandri-0.1.0a1/mandri/adapters/config/toml/store.py +37 -0
- mandri-0.1.0a1/mandri/adapters/credentials/__init__.py +4 -0
- mandri-0.1.0a1/mandri/adapters/credentials/permissions.py +26 -0
- mandri-0.1.0a1/mandri/adapters/credentials/toml.py +40 -0
- mandri-0.1.0a1/mandri/adapters/credentials/windows_acl.py +209 -0
- mandri-0.1.0a1/mandri/adapters/credentials/windows_dacl.py +54 -0
- mandri-0.1.0a1/mandri/adapters/filesystem/__init__.py +3 -0
- mandri-0.1.0a1/mandri/adapters/filesystem/atomic.py +25 -0
- mandri-0.1.0a1/mandri/adapters/llm/__init__.py +12 -0
- mandri-0.1.0a1/mandri/adapters/llm/lmstudio.py +53 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/__init__.py +17 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/constants.py +9 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/http_client.py +97 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/provider.py +140 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/request_codec.py +222 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/response_codec.py +59 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/stream.py +159 -0
- mandri-0.1.0a1/mandri/adapters/llm/openai_compatible/values.py +30 -0
- mandri-0.1.0a1/mandri/adapters/llm/opencode.py +39 -0
- mandri-0.1.0a1/mandri/adapters/llm/openrouter.py +110 -0
- mandri-0.1.0a1/mandri/adapters/llm/sse.py +14 -0
- mandri-0.1.0a1/mandri/adapters/memory/__init__.py +3 -0
- mandri-0.1.0a1/mandri/adapters/memory/filesystem.py +42 -0
- mandri-0.1.0a1/mandri/adapters/memory_search/__init__.py +3 -0
- mandri-0.1.0a1/mandri/adapters/memory_search/filesystem.py +52 -0
- mandri-0.1.0a1/mandri/adapters/question/__init__.py +10 -0
- mandri-0.1.0a1/mandri/adapters/question/autopilot.py +164 -0
- mandri-0.1.0a1/mandri/adapters/question/manual.py +13 -0
- mandri-0.1.0a1/mandri/adapters/question/yolo.py +20 -0
- mandri-0.1.0a1/mandri/adapters/retry/__init__.py +5 -0
- mandri-0.1.0a1/mandri/adapters/retry/failfast.py +10 -0
- mandri-0.1.0a1/mandri/adapters/session/__init__.py +3 -0
- mandri-0.1.0a1/mandri/adapters/session/filesystem/__init__.py +45 -0
- mandri-0.1.0a1/mandri/adapters/session/filesystem/codec.py +186 -0
- mandri-0.1.0a1/mandri/adapters/session/filesystem/store.py +91 -0
- mandri-0.1.0a1/mandri/adapters/session/filesystem/values.py +46 -0
- mandri-0.1.0a1/mandri/adapters/subagent/__init__.py +12 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/__init__.py +83 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/approval.py +91 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/config.py +47 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/constants.py +18 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/factory.py +94 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/process.py +50 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/questions.py +64 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/relay.py +62 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/subagent.py +255 -0
- mandri-0.1.0a1/mandri/adapters/subagent/claude/translation.py +123 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/__init__.py +87 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/client.py +218 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/config.py +128 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/constants.py +2 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/decisions.py +113 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/factory.py +96 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/process.py +94 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/subagent.py +221 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex/translation.py +101 -0
- mandri-0.1.0a1/mandri/adapters/subagent/codex_workspace.py +75 -0
- mandri-0.1.0a1/mandri/adapters/subagent/opencode/__init__.py +41 -0
- mandri-0.1.0a1/mandri/adapters/subagent/opencode/client.py +246 -0
- mandri-0.1.0a1/mandri/adapters/subagent/opencode/config.py +53 -0
- mandri-0.1.0a1/mandri/adapters/subagent/opencode/constants.py +2 -0
- mandri-0.1.0a1/mandri/adapters/subagent/opencode/factory.py +114 -0
- mandri-0.1.0a1/mandri/adapters/subagent/opencode/subagent.py +178 -0
- mandri-0.1.0a1/mandri/adapters/subagent/opencode/translation.py +127 -0
- mandri-0.1.0a1/mandri/adapters/user_profile/__init__.py +3 -0
- mandri-0.1.0a1/mandri/adapters/user_profile/filesystem.py +28 -0
- mandri-0.1.0a1/mandri/core/__init__.py +89 -0
- mandri-0.1.0a1/mandri/core/agent/__init__.py +19 -0
- mandri-0.1.0a1/mandri/core/agent/blackboard.py +25 -0
- mandri-0.1.0a1/mandri/core/agent/context.py +33 -0
- mandri-0.1.0a1/mandri/core/agent/input.py +13 -0
- mandri-0.1.0a1/mandri/core/agent/loop.py +590 -0
- mandri-0.1.0a1/mandri/core/agent/manager.py +313 -0
- mandri-0.1.0a1/mandri/core/agent/output.py +51 -0
- mandri-0.1.0a1/mandri/core/agent/runtime.py +59 -0
- mandri-0.1.0a1/mandri/core/agent/session.py +278 -0
- mandri-0.1.0a1/mandri/core/agent/steering.py +29 -0
- mandri-0.1.0a1/mandri/core/background/__init__.py +13 -0
- mandri-0.1.0a1/mandri/core/background/manager.py +260 -0
- mandri-0.1.0a1/mandri/core/session/__init__.py +3 -0
- mandri-0.1.0a1/mandri/core/session/saver.py +60 -0
- mandri-0.1.0a1/mandri/core/tools/__init__.py +19 -0
- mandri-0.1.0a1/mandri/core/tools/agent/__init__.py +13 -0
- mandri-0.1.0a1/mandri/core/tools/agent/result.py +28 -0
- mandri-0.1.0a1/mandri/core/tools/agent/send.py +45 -0
- mandri-0.1.0a1/mandri/core/tools/agent/spawn.py +54 -0
- mandri-0.1.0a1/mandri/core/tools/agent/status.py +38 -0
- mandri-0.1.0a1/mandri/core/tools/agent/stop.py +38 -0
- mandri-0.1.0a1/mandri/core/tools/agent/wait.py +38 -0
- mandri-0.1.0a1/mandri/core/tools/executor.py +104 -0
- mandri-0.1.0a1/mandri/core/tools/registry.py +29 -0
- mandri-0.1.0a1/mandri/core/user_profile/__init__.py +3 -0
- mandri-0.1.0a1/mandri/core/user_profile/profile_updater.py +136 -0
- mandri-0.1.0a1/mandri/gateway/__init__.py +5 -0
- mandri-0.1.0a1/mandri/gateway/anthropic/__init__.py +61 -0
- mandri-0.1.0a1/mandri/gateway/anthropic/request.py +249 -0
- mandri-0.1.0a1/mandri/gateway/anthropic/response.py +96 -0
- mandri-0.1.0a1/mandri/gateway/anthropic/stream.py +130 -0
- mandri-0.1.0a1/mandri/gateway/anthropic/values.py +82 -0
- mandri-0.1.0a1/mandri/gateway/decode.py +240 -0
- mandri-0.1.0a1/mandri/gateway/encode.py +198 -0
- mandri-0.1.0a1/mandri/gateway/errors.py +43 -0
- mandri-0.1.0a1/mandri/gateway/execution.py +121 -0
- mandri-0.1.0a1/mandri/gateway/handlers.py +157 -0
- mandri-0.1.0a1/mandri/gateway/http.py +85 -0
- mandri-0.1.0a1/mandri/gateway/responses/__init__.py +92 -0
- mandri-0.1.0a1/mandri/gateway/responses/messages.py +190 -0
- mandri-0.1.0a1/mandri/gateway/responses/request.py +143 -0
- mandri-0.1.0a1/mandri/gateway/responses/response.py +143 -0
- mandri-0.1.0a1/mandri/gateway/responses/stream.py +304 -0
- mandri-0.1.0a1/mandri/gateway/responses/tools.py +155 -0
- mandri-0.1.0a1/mandri/gateway/responses/tunnel.py +16 -0
- mandri-0.1.0a1/mandri/gateway/responses/values.py +106 -0
- mandri-0.1.0a1/mandri/gateway/routing.py +104 -0
- mandri-0.1.0a1/mandri/gateway/server.py +109 -0
- mandri-0.1.0a1/mandri/gateway/wire.py +12 -0
- mandri-0.1.0a1/mandri/logging.py +82 -0
- mandri-0.1.0a1/mandri/mcp/__init__.py +3 -0
- mandri-0.1.0a1/mandri/mcp/server.py +131 -0
- mandri-0.1.0a1/mandri/ports/__init__.py +0 -0
- mandri-0.1.0a1/mandri/ports/agent/__init__.py +61 -0
- mandri-0.1.0a1/mandri/ports/agent/context.py +7 -0
- mandri-0.1.0a1/mandri/ports/agent/events.py +171 -0
- mandri-0.1.0a1/mandri/ports/agent/input.py +9 -0
- mandri-0.1.0a1/mandri/ports/agent/runtime.py +25 -0
- mandri-0.1.0a1/mandri/ports/approval/__init__.py +7 -0
- mandri-0.1.0a1/mandri/ports/approval/port.py +23 -0
- mandri-0.1.0a1/mandri/ports/background/__init__.py +8 -0
- mandri-0.1.0a1/mandri/ports/background/handle.py +34 -0
- mandri-0.1.0a1/mandri/ports/background/port.py +66 -0
- mandri-0.1.0a1/mandri/ports/config/__init__.py +31 -0
- mandri-0.1.0a1/mandri/ports/config/port.py +212 -0
- mandri-0.1.0a1/mandri/ports/credentials/__init__.py +3 -0
- mandri-0.1.0a1/mandri/ports/credentials/port.py +7 -0
- mandri-0.1.0a1/mandri/ports/gateway/__init__.py +8 -0
- mandri-0.1.0a1/mandri/ports/gateway/port.py +32 -0
- mandri-0.1.0a1/mandri/ports/llm/__init__.py +90 -0
- mandri-0.1.0a1/mandri/ports/llm/capabilities.py +25 -0
- mandri-0.1.0a1/mandri/ports/llm/content.py +65 -0
- mandri-0.1.0a1/mandri/ports/llm/errors.py +44 -0
- mandri-0.1.0a1/mandri/ports/llm/messages.py +19 -0
- mandri-0.1.0a1/mandri/ports/llm/output.py +16 -0
- mandri-0.1.0a1/mandri/ports/llm/passthrough.py +5 -0
- mandri-0.1.0a1/mandri/ports/llm/port.py +20 -0
- mandri-0.1.0a1/mandri/ports/llm/request.py +32 -0
- mandri-0.1.0a1/mandri/ports/llm/response.py +36 -0
- mandri-0.1.0a1/mandri/ports/llm/stream.py +61 -0
- mandri-0.1.0a1/mandri/ports/llm/tools.py +28 -0
- mandri-0.1.0a1/mandri/ports/mcp/__init__.py +3 -0
- mandri-0.1.0a1/mandri/ports/mcp/port.py +12 -0
- mandri-0.1.0a1/mandri/ports/memory/__init__.py +3 -0
- mandri-0.1.0a1/mandri/ports/memory/port.py +28 -0
- mandri-0.1.0a1/mandri/ports/memory_search/__init__.py +3 -0
- mandri-0.1.0a1/mandri/ports/memory_search/port.py +9 -0
- mandri-0.1.0a1/mandri/ports/question/__init__.py +19 -0
- mandri-0.1.0a1/mandri/ports/question/models.py +36 -0
- mandri-0.1.0a1/mandri/ports/question/port.py +18 -0
- mandri-0.1.0a1/mandri/ports/retry/__init__.py +6 -0
- mandri-0.1.0a1/mandri/ports/retry/port.py +10 -0
- mandri-0.1.0a1/mandri/ports/session/__init__.py +3 -0
- mandri-0.1.0a1/mandri/ports/session/port.py +30 -0
- mandri-0.1.0a1/mandri/ports/subagent/__init__.py +24 -0
- mandri-0.1.0a1/mandri/ports/subagent/observer.py +16 -0
- mandri-0.1.0a1/mandri/ports/subagent/port.py +70 -0
- mandri-0.1.0a1/mandri/ports/tools/__init__.py +10 -0
- mandri-0.1.0a1/mandri/ports/tools/executor.py +15 -0
- mandri-0.1.0a1/mandri/ports/tools/port.py +32 -0
- mandri-0.1.0a1/mandri/ports/user_profile/__init__.py +3 -0
- mandri-0.1.0a1/mandri/ports/user_profile/port.py +16 -0
- mandri-0.1.0a1/mandri/prompts/__init__.py +3 -0
- mandri-0.1.0a1/mandri/prompts/approval.py +8 -0
- mandri-0.1.0a1/mandri/prompts/question.py +3 -0
- mandri-0.1.0a1/mandri/prompts/system_prompt.py +37 -0
- mandri-0.1.0a1/mandri/prompts/user_profile.py +5 -0
- mandri-0.1.0a1/mandri/py.typed +0 -0
- mandri-0.1.0a1/mandri_tui/__init__.py +3 -0
- mandri-0.1.0a1/mandri_tui/__main__.py +27 -0
- mandri-0.1.0a1/mandri_tui/app/__init__.py +22 -0
- mandri-0.1.0a1/mandri_tui/app/base.py +301 -0
- mandri-0.1.0a1/mandri_tui/app/input.py +186 -0
- mandri-0.1.0a1/mandri_tui/app/lifecycle.py +157 -0
- mandri-0.1.0a1/mandri_tui/app/models.py +255 -0
- mandri-0.1.0a1/mandri_tui/app/observer.py +175 -0
- mandri-0.1.0a1/mandri_tui/app/sessions.py +217 -0
- mandri-0.1.0a1/mandri_tui/app/startup.py +229 -0
- mandri-0.1.0a1/mandri_tui/app/turns.py +63 -0
- mandri-0.1.0a1/mandri_tui/approval.py +170 -0
- mandri-0.1.0a1/mandri_tui/attachments.py +153 -0
- mandri-0.1.0a1/mandri_tui/background_indicator.py +183 -0
- mandri-0.1.0a1/mandri_tui/blocks.py +234 -0
- mandri-0.1.0a1/mandri_tui/catalog.py +165 -0
- mandri-0.1.0a1/mandri_tui/commands.py +90 -0
- mandri-0.1.0a1/mandri_tui/composer.py +84 -0
- mandri-0.1.0a1/mandri_tui/formatting.py +89 -0
- mandri-0.1.0a1/mandri_tui/model_selection.py +43 -0
- mandri-0.1.0a1/mandri_tui/runtime.py +232 -0
- mandri-0.1.0a1/mandri_tui/screens/__init__.py +18 -0
- mandri-0.1.0a1/mandri_tui/screens/approval.py +82 -0
- mandri-0.1.0a1/mandri_tui/screens/model.py +128 -0
- mandri-0.1.0a1/mandri_tui/screens/provider.py +102 -0
- mandri-0.1.0a1/mandri_tui/screens/question.py +79 -0
- mandri-0.1.0a1/mandri_tui/screens/session.py +53 -0
- mandri-0.1.0a1/mandri_tui/suggestions.py +13 -0
- mandri-0.1.0a1/mandri_tui/text_attachments.py +94 -0
- mandri-0.1.0a1/mandri_tui/transcript/__init__.py +6 -0
- mandri-0.1.0a1/mandri_tui/transcript/log.py +90 -0
- mandri-0.1.0a1/mandri_tui/transcript/renderer.py +311 -0
- mandri-0.1.0a1/mandri_tui/transcript/screen.py +44 -0
- mandri-0.1.0a1/mandri_tui/transcript/subagent.py +105 -0
- mandri-0.1.0a1/mandri_tui/tui.tcss +983 -0
- mandri-0.1.0a1/mandri_tui/welcome.py +72 -0
- mandri-0.1.0a1/mandri_tui/wiring.py +42 -0
- mandri-0.1.0a1/pyproject.toml +78 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Python-generated files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[oc]
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
wheels/
|
|
7
|
+
*.egg-info
|
|
8
|
+
|
|
9
|
+
# Virtual environments
|
|
10
|
+
.venv
|
|
11
|
+
|
|
12
|
+
.env
|
|
13
|
+
.env.*
|
|
14
|
+
!.env.example
|
|
15
|
+
.pypirc
|
|
16
|
+
.npmrc
|
|
17
|
+
credentials.toml
|
|
18
|
+
secrets.toml
|
|
19
|
+
*.pem
|
|
20
|
+
*.key
|
|
21
|
+
id_rsa
|
|
22
|
+
id_ed25519
|
|
23
|
+
workspace/*
|
|
24
|
+
!workspace/.gitkeep
|
|
25
|
+
|
|
26
|
+
# Claude Code local settings
|
|
27
|
+
.claude/settings.local.json
|
|
28
|
+
CLAUDE.local.md
|
|
29
|
+
|
|
30
|
+
# node / web
|
|
31
|
+
node_modules/
|
|
32
|
+
web/dist/
|
|
33
|
+
assistant/server/static/
|
|
34
|
+
|
|
35
|
+
# ruff
|
|
36
|
+
.ruff_cache/
|
|
37
|
+
|
|
38
|
+
# model metadata cache
|
|
39
|
+
.cache/
|
|
40
|
+
|
|
41
|
+
# cloud-session transfer artifacts
|
|
42
|
+
*.bundle
|
|
43
|
+
*.patch
|
|
44
|
+
|
|
45
|
+
# TS incremental build cache
|
|
46
|
+
web/*.tsbuildinfo
|
|
47
|
+
|
|
48
|
+
# Scratchpads
|
|
49
|
+
.scratch/
|
|
50
|
+
tmp/
|
|
51
|
+
.test-tmp/
|
|
52
|
+
.pytest-tmp/
|
|
53
|
+
|
|
54
|
+
# Stories artifacts
|
|
55
|
+
.artifacts/
|
mandri-0.1.0a1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
mandri-0.1.0a1/PKG-INFO
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mandri
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Turn agents into a team
|
|
5
|
+
Project-URL: Homepage, https://github.com/mandri-labs/mandri
|
|
6
|
+
Project-URL: Repository, https://github.com/mandri-labs/mandri
|
|
7
|
+
Project-URL: Issues, https://github.com/mandri-labs/mandri/issues
|
|
8
|
+
Author-email: Mandri Labs <labs@mandri.io>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,ai,orchestration
|
|
12
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.13
|
|
17
|
+
Requires-Dist: agent-client-protocol>=0.11.0
|
|
18
|
+
Requires-Dist: aiohttp>=3.14.3
|
|
19
|
+
Requires-Dist: charset-normalizer>=3.4.9
|
|
20
|
+
Requires-Dist: httpx>=0.28.1
|
|
21
|
+
Requires-Dist: mcp<2,>=1.12
|
|
22
|
+
Requires-Dist: packaging>=26.0
|
|
23
|
+
Requires-Dist: rich>=15.0.0
|
|
24
|
+
Requires-Dist: starlette>=1.3.1
|
|
25
|
+
Requires-Dist: textual>=8.2.8
|
|
26
|
+
Requires-Dist: uvicorn>=0.51.0
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
> [!WARNING]
|
|
30
|
+
> Mandri is in alpha - expect bugs and breaking changes.
|
|
31
|
+
|
|
32
|
+
# Mandri
|
|
33
|
+
|
|
34
|
+
Mandri is an open, local-first orchestrator for autonomous agents.
|
|
35
|
+
|
|
36
|
+
For a simple task, Mandri can delegate the work to a single agent. If that
|
|
37
|
+
agent gets stuck, it can bring in another agent with a different model,
|
|
38
|
+
runtime, or set of capabilities.
|
|
39
|
+
|
|
40
|
+
For complex tasks, Mandri coordinates multiple specialist agents, allowing
|
|
41
|
+
them to exchange requests, findings, and results while working toward the
|
|
42
|
+
same outcome.
|
|
43
|
+
|
|
44
|
+
## Built on proven agents
|
|
45
|
+
|
|
46
|
+
Mandri does not try to rebuild coding, browser, or terminal agents from
|
|
47
|
+
scratch.
|
|
48
|
+
|
|
49
|
+
It orchestrates agents that already know how to do their job, such as Claude
|
|
50
|
+
Code, Codex, OpenCode, and other specialized runtimes, and gives them a way to
|
|
51
|
+
delegate work, exchange context, and coordinate around the same task.
|
|
52
|
+
|
|
53
|
+
Each agent keeps its own tools, execution loop, context, permissions, and
|
|
54
|
+
strengths.
|
|
55
|
+
|
|
56
|
+
## Bring your own models
|
|
57
|
+
|
|
58
|
+
Mandri separates the agent runtime from the language model behind it.
|
|
59
|
+
|
|
60
|
+
Through its model gateway, a compatible agent can use the provider or model
|
|
61
|
+
selected by the user, whether it runs locally, through a cloud API, or behind
|
|
62
|
+
any OpenAI-compatible endpoint.
|
|
63
|
+
|
|
64
|
+
## Lean by design
|
|
65
|
+
|
|
66
|
+
Mandri uses as few dependencies as possible.
|
|
67
|
+
|
|
68
|
+
It is not an all-in-one agent framework, a workflow platform, or a replacement
|
|
69
|
+
for every tool it connects to. Its purpose is narrower: delegate work,
|
|
70
|
+
coordinate agents, route communication, and keep the user in control.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
Mandri is licensed under the Apache License 2.0.
|
mandri-0.1.0a1/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
> [!WARNING]
|
|
2
|
+
> Mandri is in alpha - expect bugs and breaking changes.
|
|
3
|
+
|
|
4
|
+
# Mandri
|
|
5
|
+
|
|
6
|
+
Mandri is an open, local-first orchestrator for autonomous agents.
|
|
7
|
+
|
|
8
|
+
For a simple task, Mandri can delegate the work to a single agent. If that
|
|
9
|
+
agent gets stuck, it can bring in another agent with a different model,
|
|
10
|
+
runtime, or set of capabilities.
|
|
11
|
+
|
|
12
|
+
For complex tasks, Mandri coordinates multiple specialist agents, allowing
|
|
13
|
+
them to exchange requests, findings, and results while working toward the
|
|
14
|
+
same outcome.
|
|
15
|
+
|
|
16
|
+
## Built on proven agents
|
|
17
|
+
|
|
18
|
+
Mandri does not try to rebuild coding, browser, or terminal agents from
|
|
19
|
+
scratch.
|
|
20
|
+
|
|
21
|
+
It orchestrates agents that already know how to do their job, such as Claude
|
|
22
|
+
Code, Codex, OpenCode, and other specialized runtimes, and gives them a way to
|
|
23
|
+
delegate work, exchange context, and coordinate around the same task.
|
|
24
|
+
|
|
25
|
+
Each agent keeps its own tools, execution loop, context, permissions, and
|
|
26
|
+
strengths.
|
|
27
|
+
|
|
28
|
+
## Bring your own models
|
|
29
|
+
|
|
30
|
+
Mandri separates the agent runtime from the language model behind it.
|
|
31
|
+
|
|
32
|
+
Through its model gateway, a compatible agent can use the provider or model
|
|
33
|
+
selected by the user, whether it runs locally, through a cloud API, or behind
|
|
34
|
+
any OpenAI-compatible endpoint.
|
|
35
|
+
|
|
36
|
+
## Lean by design
|
|
37
|
+
|
|
38
|
+
Mandri uses as few dependencies as possible.
|
|
39
|
+
|
|
40
|
+
It is not an all-in-one agent framework, a workflow platform, or a replacement
|
|
41
|
+
for every tool it connects to. Its purpose is narrower: delegate work,
|
|
42
|
+
coordinate agents, route communication, and keep the user in control.
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
Mandri is licensed under the Apache License 2.0.
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
from mandri.ports.approval import ApprovalDecision
|
|
5
|
+
from mandri.ports.llm import (
|
|
6
|
+
JsonObjectOutput,
|
|
7
|
+
LLMProviderPort,
|
|
8
|
+
LLMRequest,
|
|
9
|
+
Message,
|
|
10
|
+
Role,
|
|
11
|
+
TextPart,
|
|
12
|
+
ToolCallPart,
|
|
13
|
+
)
|
|
14
|
+
from mandri.prompts.approval import AUTOPILOT_APPROVAL_PROMPT
|
|
15
|
+
|
|
16
|
+
_logger = logging.getLogger(__name__)
|
|
17
|
+
_SAFE_RISKS = frozenset(("LOW", "MEDIUM"))
|
|
18
|
+
_DECISION_SCHEMA = {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {
|
|
21
|
+
"tool_call_id": {"type": "string"},
|
|
22
|
+
"risk": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"enum": ["LOW", "MEDIUM", "HIGH", "UNKNOWN"],
|
|
25
|
+
},
|
|
26
|
+
"reason": {"type": "string"},
|
|
27
|
+
},
|
|
28
|
+
"required": ["tool_call_id", "risk", "reason"],
|
|
29
|
+
"additionalProperties": False,
|
|
30
|
+
}
|
|
31
|
+
_VERDICT_SCHEMA = {
|
|
32
|
+
"type": "object",
|
|
33
|
+
"properties": {
|
|
34
|
+
"decisions": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": _DECISION_SCHEMA,
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"required": ["decisions"],
|
|
40
|
+
"additionalProperties": False,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class AutopilotApprovalPolicy:
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
provider: LLMProviderPort,
|
|
48
|
+
*,
|
|
49
|
+
model: str,
|
|
50
|
+
) -> None:
|
|
51
|
+
self._provider = provider
|
|
52
|
+
self._model = model
|
|
53
|
+
|
|
54
|
+
async def request(
|
|
55
|
+
self, calls: tuple[ToolCallPart, ...]
|
|
56
|
+
) -> tuple[ApprovalDecision, ...]:
|
|
57
|
+
if not calls:
|
|
58
|
+
return ()
|
|
59
|
+
try:
|
|
60
|
+
response = await self._provider.generate(self._request(calls))
|
|
61
|
+
verdicts = _verdicts(response.message, calls)
|
|
62
|
+
except Exception:
|
|
63
|
+
_logger.exception(
|
|
64
|
+
"autopilot approval failed tools=%s",
|
|
65
|
+
",".join(call.tool_name for call in calls),
|
|
66
|
+
)
|
|
67
|
+
return tuple(
|
|
68
|
+
ApprovalDecision(
|
|
69
|
+
approved=False,
|
|
70
|
+
feedback="Autopilot could not assess this tool call",
|
|
71
|
+
)
|
|
72
|
+
for _ in calls
|
|
73
|
+
)
|
|
74
|
+
return tuple(_decision(risk, reason) for risk, reason in verdicts)
|
|
75
|
+
|
|
76
|
+
def _request(self, calls: tuple[ToolCallPart, ...]) -> LLMRequest:
|
|
77
|
+
payload = json.dumps(
|
|
78
|
+
{
|
|
79
|
+
"tool_calls": [
|
|
80
|
+
{
|
|
81
|
+
"tool_call_id": call.tool_call_id,
|
|
82
|
+
"tool": call.tool_name,
|
|
83
|
+
"arguments": call.arguments,
|
|
84
|
+
}
|
|
85
|
+
for call in calls
|
|
86
|
+
],
|
|
87
|
+
"output_format": "json",
|
|
88
|
+
"output_schema": _VERDICT_SCHEMA,
|
|
89
|
+
},
|
|
90
|
+
ensure_ascii=False,
|
|
91
|
+
)
|
|
92
|
+
return LLMRequest(
|
|
93
|
+
model=self._model,
|
|
94
|
+
messages=(
|
|
95
|
+
Message(
|
|
96
|
+
role=Role.SYSTEM,
|
|
97
|
+
parts=(TextPart(text=AUTOPILOT_APPROVAL_PROMPT),),
|
|
98
|
+
),
|
|
99
|
+
Message(role=Role.USER, parts=(TextPart(text=payload),)),
|
|
100
|
+
),
|
|
101
|
+
output=JsonObjectOutput(),
|
|
102
|
+
max_output_tokens=4096,
|
|
103
|
+
temperature=0.0,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _verdicts(
|
|
108
|
+
message: Message, calls: tuple[ToolCallPart, ...]
|
|
109
|
+
) -> tuple[tuple[str, str], ...]:
|
|
110
|
+
content = "".join(part.text for part in message.parts if isinstance(part, TextPart))
|
|
111
|
+
verdict = json.loads(content)
|
|
112
|
+
if not isinstance(verdict, dict):
|
|
113
|
+
raise ValueError("autopilot verdict must be an object")
|
|
114
|
+
decisions = verdict.get("decisions")
|
|
115
|
+
if not isinstance(decisions, list) or len(decisions) != len(calls):
|
|
116
|
+
raise ValueError("autopilot verdict count does not match tool calls")
|
|
117
|
+
by_id = {_decision_id(item): item for item in decisions}
|
|
118
|
+
if len(by_id) != len(decisions):
|
|
119
|
+
raise ValueError("autopilot verdict has duplicate tool call ids")
|
|
120
|
+
return tuple(_risk_reason(by_id.get(call.tool_call_id)) for call in calls)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _decision_id(verdict: object) -> str:
|
|
124
|
+
if not isinstance(verdict, dict):
|
|
125
|
+
raise ValueError("autopilot decision must be an object")
|
|
126
|
+
tool_call_id = verdict.get("tool_call_id")
|
|
127
|
+
if not isinstance(tool_call_id, str) or not tool_call_id:
|
|
128
|
+
raise ValueError("autopilot decision has no tool call id")
|
|
129
|
+
return tool_call_id
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _risk_reason(verdict: object) -> tuple[str, str]:
|
|
133
|
+
if not isinstance(verdict, dict):
|
|
134
|
+
raise ValueError("autopilot decision must be an object")
|
|
135
|
+
risk = verdict.get("risk")
|
|
136
|
+
reason = verdict.get("reason")
|
|
137
|
+
if risk not in {"LOW", "MEDIUM", "HIGH", "UNKNOWN"}:
|
|
138
|
+
raise ValueError("autopilot verdict has an invalid risk")
|
|
139
|
+
if not isinstance(reason, str) or not reason.strip():
|
|
140
|
+
raise ValueError("autopilot verdict has no reason")
|
|
141
|
+
return risk, reason.strip()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _decision(risk: str, reason: str) -> ApprovalDecision:
|
|
145
|
+
if risk in _SAFE_RISKS:
|
|
146
|
+
return ApprovalDecision(approved=True)
|
|
147
|
+
return ApprovalDecision(
|
|
148
|
+
approved=False,
|
|
149
|
+
feedback=f"Autopilot classified this tool call as {risk}: {reason}",
|
|
150
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from mandri.ports.approval import ApprovalDecision, ApprovalPolicyPort
|
|
4
|
+
from mandri.ports.llm import ToolCallPart
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ApprovalBatcher:
|
|
8
|
+
def __init__(self, policy: ApprovalPolicyPort) -> None:
|
|
9
|
+
self._policy = policy
|
|
10
|
+
self._decisions: dict[str, ApprovalDecision] = {}
|
|
11
|
+
self._lock = asyncio.Lock()
|
|
12
|
+
|
|
13
|
+
def set_policy(self, policy: ApprovalPolicyPort) -> None:
|
|
14
|
+
self._policy = policy
|
|
15
|
+
|
|
16
|
+
async def request(
|
|
17
|
+
self,
|
|
18
|
+
call: ToolCallPart,
|
|
19
|
+
batch: tuple[ToolCallPart, ...] = (),
|
|
20
|
+
) -> ApprovalDecision:
|
|
21
|
+
async with self._lock:
|
|
22
|
+
cached = self._decisions.pop(call.tool_call_id, None)
|
|
23
|
+
if cached is not None:
|
|
24
|
+
return cached
|
|
25
|
+
calls = self._unresolved(call, batch)
|
|
26
|
+
decisions = await self._policy.request(calls)
|
|
27
|
+
if len(decisions) != len(calls):
|
|
28
|
+
raise ValueError("approval decision count does not match calls")
|
|
29
|
+
self._decisions.update(
|
|
30
|
+
(candidate.tool_call_id, decision)
|
|
31
|
+
for candidate, decision in zip(calls, decisions, strict=True)
|
|
32
|
+
)
|
|
33
|
+
decision = self._decisions.pop(call.tool_call_id, None)
|
|
34
|
+
if decision is None:
|
|
35
|
+
raise ValueError("approval batch does not contain requested call")
|
|
36
|
+
return decision
|
|
37
|
+
|
|
38
|
+
def discard(self, tool_call_id: str) -> None:
|
|
39
|
+
self._decisions.pop(tool_call_id, None)
|
|
40
|
+
|
|
41
|
+
def clear(self) -> None:
|
|
42
|
+
self._decisions.clear()
|
|
43
|
+
|
|
44
|
+
def _unresolved(
|
|
45
|
+
self,
|
|
46
|
+
call: ToolCallPart,
|
|
47
|
+
batch: tuple[ToolCallPart, ...],
|
|
48
|
+
) -> tuple[ToolCallPart, ...]:
|
|
49
|
+
calls = {
|
|
50
|
+
candidate.tool_call_id: candidate
|
|
51
|
+
for candidate in (*batch, call)
|
|
52
|
+
if candidate.tool_call_id not in self._decisions
|
|
53
|
+
}
|
|
54
|
+
return tuple(calls.values())
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from collections.abc import Awaitable, Callable
|
|
2
|
+
|
|
3
|
+
from mandri.ports.approval import ApprovalDecision
|
|
4
|
+
from mandri.ports.llm import ToolCallPart
|
|
5
|
+
|
|
6
|
+
type ApprovalPrompt = Callable[[ToolCallPart], Awaitable[ApprovalDecision]]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ManualApprovalPolicy:
|
|
10
|
+
def __init__(self, prompt: ApprovalPrompt) -> None:
|
|
11
|
+
self._prompt = prompt
|
|
12
|
+
|
|
13
|
+
async def request(
|
|
14
|
+
self, calls: tuple[ToolCallPart, ...]
|
|
15
|
+
) -> tuple[ApprovalDecision, ...]:
|
|
16
|
+
decisions: list[ApprovalDecision] = []
|
|
17
|
+
for call in calls:
|
|
18
|
+
decisions.append(await self._prompt(call))
|
|
19
|
+
return tuple(decisions)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from mandri.ports.approval import ApprovalDecision
|
|
2
|
+
from mandri.ports.llm import ToolCallPart
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class YoloApprovalPolicy:
|
|
6
|
+
async def request(
|
|
7
|
+
self, calls: tuple[ToolCallPart, ...]
|
|
8
|
+
) -> tuple[ApprovalDecision, ...]:
|
|
9
|
+
return tuple(ApprovalDecision(approved=True) for _ in calls)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from .decode import (
|
|
2
|
+
_approval_mode,
|
|
3
|
+
_model_config,
|
|
4
|
+
_non_negative_int,
|
|
5
|
+
_optional_string,
|
|
6
|
+
_orchestrator,
|
|
7
|
+
_positive_int,
|
|
8
|
+
_providers,
|
|
9
|
+
_required_string,
|
|
10
|
+
_role,
|
|
11
|
+
_table,
|
|
12
|
+
_user_profile,
|
|
13
|
+
from_toml,
|
|
14
|
+
)
|
|
15
|
+
from .encode import (
|
|
16
|
+
_serialize_role,
|
|
17
|
+
to_toml,
|
|
18
|
+
)
|
|
19
|
+
from .store import (
|
|
20
|
+
TomlConfig,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"TomlConfig",
|
|
25
|
+
"_approval_mode",
|
|
26
|
+
"_model_config",
|
|
27
|
+
"_non_negative_int",
|
|
28
|
+
"_optional_string",
|
|
29
|
+
"_orchestrator",
|
|
30
|
+
"_positive_int",
|
|
31
|
+
"_providers",
|
|
32
|
+
"_required_string",
|
|
33
|
+
"_role",
|
|
34
|
+
"_serialize_role",
|
|
35
|
+
"_table",
|
|
36
|
+
"_user_profile",
|
|
37
|
+
"from_toml",
|
|
38
|
+
"to_toml",
|
|
39
|
+
]
|