Repository navigation
feat(runtime): governed agent core re-engineered from Microsoft Agent… #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
96d71ec
feat(runtime): governed agent core re-engineered from Microsoft Agent…
claude 7600d99
Merge branch 'main' into feat/runtime-core
quantum-osiris bde2338
Merge branch 'main' into feat/runtime-core
quantum-osiris b2d3985
Add pattern for matching environment files
quantum-osiris 1bc30ab
Add provenance to governance data structure
quantum-osiris 86956f8
Refactor governance assignment in _agents.py
quantum-osiris 7434932
Refactor governance evidence processing logic
quantum-osiris 8462006
Handle missing parameters by assigning defaults
quantum-osiris 1179a26
Allow write effects to bypass approval mode
quantum-osiris 05854d4
Validate session history path resolution
quantum-osiris e480967
Enhance span context manager for exception handling
quantum-osiris 514e982
test(runtime): writes need the operator's approval (follow-up to 1179…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Third-party notices | ||
|
|
||
| osiris-cli is licensed under the OSIRIS Source-Available Dual License (see `LICENSE`). The | ||
| components below include material from third parties under their own licenses. Those licenses | ||
| continue to apply to that material. | ||
|
|
||
| ## Microsoft Agent Framework | ||
|
|
||
| - Source: https://github.com/microsoft/agent-framework | ||
| - Commit: `567e4d458b59b83ac9b19088a43a2853094c6df1` (2026-12-04) | ||
| - Used in: `osiris_cli/runtime/` (files whose header says "Portions adapted from | ||
| microsoft/agent-framework"). `osiris_cli/runtime/PORT_MAP.md` lists each file, the source file | ||
| it adapts, and what changed. | ||
| - License: MIT | ||
|
|
||
| ``` | ||
| MIT License | ||
|
|
||
| Copyright (c) Microsoft Corporation. | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE | ||
| ``` | ||
|
|
||
| "Microsoft" and "Agent Framework" are used here only to identify the source of the adapted | ||
| material. osiris-cli is not affiliated with or endorsed by Microsoft. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "schema": "osiris.runtime-policy.v1", | ||
| "governance_required": true, | ||
| "blocked_risk_tiers": ["CRITICAL"], | ||
| "grant_required_risk_tiers": ["HIGH"], | ||
| "credential_name_patterns": [ | ||
| ".env", | ||
| ".env.*", | ||
| "*.env", | ||
| "apikey.json", | ||
| "*credentials*", | ||
| "*secret*", | ||
| "*token*", | ||
| "id_rsa*", | ||
| "id_ed25519*", | ||
| "*.pem", | ||
| "*.key", | ||
| ".netrc" | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| Portions of osiris_cli/runtime are adapted from microsoft/agent-framework | ||
| (commit 567e4d458b59b83ac9b19088a43a2853094c6df1), used under the following license. | ||
|
|
||
| MIT License | ||
|
|
||
| Copyright (c) Microsoft Corporation. | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # osiris_cli.runtime port map | ||
|
|
||
| Phase 1 of re-engineering Microsoft Agent Framework (MAF) into osiris-cli. | ||
|
|
||
| - **Source:** `microsoft/agent-framework` at `567e4d458b59b83ac9b19088a43a2853094c6df1` (2026-12-04), MIT. License text: `THIRD_PARTY_NOTICES.md` in the repo and `LICENSE-agent-framework.txt` in this package (shipped in the wheel). | ||
| - **Method:** each MAF module was read, then rebuilt here as a smaller module that keeps its design and semantics. This is a re-implementation guided by the source, not a line-for-line copy. Files that adapt MAF code carry a header naming the source file. | ||
| - **Size:** MAF's Python core is about 86,000 lines. This runtime is about 2,400 lines of code and 1,400 lines of tests. | ||
|
|
||
| ## Files | ||
|
|
||
| | OSIRIS file | MAF source (python/packages/…) | What was taken | What changed | | ||
| |---|---|---|---| | ||
| | `_types.py` | `core/agent_framework/_types.py` | Message, Content, UsageDetails, ChatResponse, AgentResponse and their streaming updates | Five content kinds only (text, function call, function result, error, usage). Plain dataclasses with canonical JSON and SHA-256 helpers for ledger digests. No multimodal, annotation, hosted-tool or continuation types. | | ||
| | `_middleware.py` | `core/agent_framework/_middleware.py` | Agent, function and chat contexts; three base classes; `MiddlewareTermination`; `MiddlewareFailure`; decorator helpers; index-based pipeline execution | Unrecognized middleware raises `TypeError` (MAF logs and skips it, which would fail open). Every context carries a `RunState` shared by the run's three pipelines. No stream hooks or result gates. | | ||
| | `_tools.py` | `core/agent_framework/_tools.py` | `FunctionTool`, `@tool`, `approval_mode`, schema-checked arguments, `FunctionInvocationConfiguration` (here `InvocationConfig`) | Schema from type hints without pydantic, checked by `providers.schema_guard` and offered through `providers.tool_shim`. Adds the `effects`, `path_params`, `write_params` and `code_params` declarations that governance enforces. | | ||
| | `_clients.py` | `core/agent_framework/_clients.py`, `anthropic/` | Chat-client protocol (complete and streamed response); Anthropic message and tool-use mapping | `ProviderChatClient` wraps the existing `osiris_cli.providers` instead of replacing them. Malformed tool calls fail closed. The Anthropic client needs an explicit model id and never reads a key itself. | | ||
| | `_agents.py` | `core/agent_framework/_agents.py`, `_tools.py` | `Agent.run` / `run_stream` around three pipelines; the function-invocation loop and its limits; error wording; settling a batch when the loop stops | Tool calls run sequentially. Approvals are decided in the run by a handler (no stored approvals to replay). `run_stream` is buffered until governance passes the run. Arguments are validated before middleware sees a call. | | ||
| | `_sessions.py` | `core/agent_framework/_sessions.py` | `AgentSession`, `HistoryProvider`, `ContextProvider` | `FileHistoryProvider` writes hash-chained JSONL and refuses an edited history. It is opt-in, in a directory the caller names; it holds conversation state, never run provenance. | | ||
| | `_telemetry.py` | `core/agent_framework/observability.py` | OpenTelemetry GenAI attribute names; one span per agent run, model call and tool call | Spans are always recorded in-process; OpenTelemetry is used only when installed. The span summary (with a timing-free SHA-256) goes into the task ledger's `task_close`. | | ||
| | `_governance.py` | — (OSIRIS only) | — | Binds the hooks to existing OSIRIS governance: `task_context` (ledger, budget), `intent_router` (risk tier), `evidence_firewall`, `governance_scope`, `ast_firewall` (SYS-025), `exec_policy` + `exec_kernel`. | | ||
| | `testing.py`, `demo.py` | — (OSIRIS only) | — | Scripted chat client; end-to-end demo with an Ollama preflight before any ledger write. | | ||
|
|
||
| Tests: `tests/test_runtime_{middleware,tools,agent,clients,governance,sessions_telemetry}.py`. The cases mirrored from MAF's `core/tests` name the source test file in their module docstring. | ||
|
|
||
| ## Governance order (outermost first) | ||
|
|
||
| - **Agent:** RunRecord → Telemetry → IntentGate → EvidenceFirewall → *caller's agent middleware* → core loop | ||
| - **Chat:** Telemetry → Budget → Provenance → *caller's chat middleware* → client | ||
| - **Function:** Telemetry → *caller's function middleware* → ToolPolicy → tool | ||
|
|
||
| ToolPolicy is innermost, so it checks the arguments that will actually run. The stack can be left out only when `osiris_cli/policy/runtime_policy.json` says `"governance_required": false`. That file sits in a governance-protected directory. | ||
|
|
||
| ## Not ported in Phase 1 | ||
|
|
||
| | MAF area | Why not now | | ||
| |---|---| | ||
| | Workflows (`_workflows/`, about 12k lines) and `orchestrations` | Phase 2 | | ||
| | MCP client and server (`_mcp.py`, `hosting-mcp`) | Phase 3 | | ||
| | Compaction strategies (`_compaction.py`) | Phase 3 (`osiris.runtime.context` has a bounded broker already) | | ||
| | Information-flow security labels (`security.py`) | Phase 4 | | ||
| | Harness: tool-approval rules, judge loop, todo, background agents, file access, memory | Phase 3 | | ||
| | Evaluation (`_evaluation.py`) | Phase 3, writing into the claims register | | ||
| | Skills (`_skills.py`) | osiris-cli has `skills_runtime.py`; compare before porting anything | | ||
| | A2A, AG-UI, Responses hosting, DevUI, declarative YAML | Phase 4 (`.dna` to declarative specs) | | ||
| | Vector stores and memory backends | Later | | ||
| | Azure, Foundry, Purview, Copilot Studio, Bedrock, the other vendor packages; .NET; Go | Out of scope | | ||
| | Concurrent tool calls, unbuffered streaming, stored-approval replay, hosted tools, multimodal content | Deliberately left out (see deviations above) | | ||
|
|
||
| ## Relation to `osiris.runtime` | ||
|
|
||
| osiris-cli also has `osiris/runtime/`, about 1,500 lines of opt-in primitives: contracts, a policy decision, a SQLite session store, a scheduler, workspace tools, an isolation backend, and an MCP registration registry. It has no model-client layer, middleware or agent loop, and its only user outside tests is `osiris_launcher.py` (capability status). | ||
|
|
||
| This package does not import or change it. The two overlap on policy hooks, traces, context compaction and session storage. Before merge, decide whether to keep both, rename this package, or fold `osiris.runtime`'s primitives into these hooks in Phase 2. | ||
|
|
||
| ## Change outside the package | ||
|
|
||
| `osiris_cli/task_context.py`: `KINDS` gains `"agent"` so runtime runs are recorded under their own kind instead of being mislabelled `code`. `new_context` still floors the cost class at `workspace_write` and the tier at `MEDIUM` for every kind. That is conservative for read-only agents, and the ledger reason text reads "a agent task proposes local changes" even when it doesn't. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """OSIRIS runtime: governed agents, tools, middleware, sessions and telemetry. | ||
|
|
||
| Re-engineered from Microsoft Agent Framework (MIT; see THIRD_PARTY_NOTICES.md and PORT_MAP.md) with | ||
| OSIRIS's governance built in: every agent runs inside the governance stack in ``_governance``, its | ||
| runs are recorded in the canonical task ledger, and its tool calls are checked by the existing | ||
| exec policy, governance scope and SYS-025 AST firewall. | ||
|
|
||
| Quick start:: | ||
|
|
||
| from osiris_cli.runtime import Agent, GovernanceConfig, ProviderChatClient, tool | ||
| from osiris_cli.providers.ollama_compat import OllamaCompatibilityProvider | ||
|
|
||
| @tool(effects=("read",), path_params=("path",)) | ||
| def count_lines(path: str) -> int: | ||
| '''Count the lines in a workspace file.''' | ||
| with open(path, encoding="utf-8") as f: | ||
| return sum(1 for _ in f) | ||
|
|
||
| agent = Agent(ProviderChatClient(OllamaCompatibilityProvider(model="qwen2.5-coder:7b")), | ||
| tools=[count_lines], governance=GovernanceConfig(workspace_root=".")) | ||
| print(agent.run_sync("How many lines are in README.md?").text) | ||
| """ | ||
|
|
||
| from ._agents import Agent | ||
| from ._clients import AnthropicChatClient, ChatClient, ChatClientError, ProviderChatClient | ||
| from ._governance import ( | ||
| ApprovalRequest, | ||
| GovernanceConfig, | ||
| GovernancePolicyError, | ||
| GovernanceRequiredError, | ||
| GovernanceStack, | ||
| PolicyRefusal, | ||
| load_runtime_policy, | ||
| make_exec_tool, | ||
| ) | ||
| from ._middleware import ( | ||
| AgentContext, | ||
| AgentMiddleware, | ||
| ChatContext, | ||
| ChatMiddleware, | ||
| FunctionInvocationContext, | ||
| FunctionMiddleware, | ||
| MiddlewareFailure, | ||
| MiddlewareTermination, | ||
| RunState, | ||
| agent_middleware, | ||
| chat_middleware, | ||
| function_middleware, | ||
| ) | ||
| from ._sessions import ( | ||
| AgentSession, | ||
| ContextAdditions, | ||
| ContextProvider, | ||
| FileHistoryProvider, | ||
| HistoryIntegrityError, | ||
| HistoryProvider, | ||
| InMemoryHistoryProvider, | ||
| ) | ||
| from ._telemetry import SpanRecorder | ||
| from ._tools import FunctionTool, InvocationConfig, ToolArgumentError, ToolError, tool | ||
| from ._types import ( | ||
| AgentResponse, | ||
| AgentResponseUpdate, | ||
| ChatResponse, | ||
| ChatResponseUpdate, | ||
| Content, | ||
| Message, | ||
| UsageDetails, | ||
| ) | ||
|
|
||
| SOURCE_FRAMEWORK = "microsoft/agent-framework" | ||
| SOURCE_COMMIT = "567e4d458b59b83ac9b19088a43a2853094c6df1" | ||
|
|
||
| __all__ = [ | ||
| "Agent", "AgentContext", "AgentMiddleware", "AgentResponse", "AgentResponseUpdate", "AgentSession", | ||
| "AnthropicChatClient", "ApprovalRequest", "ChatClient", "ChatClientError", "ChatContext", "ChatMiddleware", | ||
| "ChatResponse", "ChatResponseUpdate", "Content", "ContextAdditions", "ContextProvider", "FileHistoryProvider", | ||
| "FunctionInvocationContext", "FunctionMiddleware", "FunctionTool", "GovernanceConfig", "GovernancePolicyError", | ||
| "GovernanceRequiredError", "GovernanceStack", "HistoryIntegrityError", "HistoryProvider", | ||
| "InMemoryHistoryProvider", "InvocationConfig", "Message", "MiddlewareFailure", "MiddlewareTermination", | ||
| "PolicyRefusal", "ProviderChatClient", "RunState", "SOURCE_COMMIT", "SOURCE_FRAMEWORK", "SpanRecorder", | ||
| "ToolArgumentError", "ToolError", "UsageDetails", "agent_middleware", "chat_middleware", "function_middleware", | ||
| "load_runtime_policy", "make_exec_tool", "tool", | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.