maigp-microsoft-agent-framework 1.0.0__py3-none-any.whl

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.
@@ -0,0 +1,27 @@
1
+ """AIGP adapter for Microsoft Agent Framework (MAF).
2
+
3
+ MAF 1.0 (GA 2026-04-03) is the converged successor to Semantic Kernel + AutoGen — a single
4
+ SDK for agents and multi-agent workflows in Python/.NET (chat clients, tools, MCP integrations,
5
+ context providers, middleware, workflows). This adapter brings MAF agents under AIGP governance
6
+ (CHECK before invoke, RECORD/TRACE after, tool-call governance) via aigp-agent-core.
7
+
8
+ It replaces the separate `aigp-autogen` and `aigp-semantic-kernel` adapters, which target the
9
+ now-merged predecessor frameworks.
10
+
11
+ Usage:
12
+ from agent_framework import ChatAgent # MAF
13
+ from aigp_microsoft_agent_framework import AigpMafGovernance
14
+
15
+ gov = AigpMafGovernance(gov_url="https://gov.example.com", app_id="my-maf-agent",
16
+ hmac_secret="secret")
17
+
18
+ agent = ChatAgent(chat_client=..., tools=[...], middleware=[gov.middleware()])
19
+ result = await gov.run(agent, "Analyze this finding", agent_name="analyst")
20
+ # ✓ CHECK before run · token usage recorded · tool calls governed · RECORD+TRACE after
21
+ """
22
+
23
+ __version__ = "1.0.0"
24
+
25
+ from .handler import AigpMafGovernance, AigpMafMiddleware
26
+
27
+ __all__ = ["AigpMafGovernance", "AigpMafMiddleware"]
@@ -0,0 +1,109 @@
1
+ """Microsoft Agent Framework (MAF) governance handler.
2
+
3
+ MAF exposes agents (e.g. ChatAgent) with a `run`/`run_stream` surface, function tools, and a
4
+ middleware chain. This adapter governs a MAF agent run through aigp-agent-core:
5
+
6
+ - run start → CHECK (pre_invoke)
7
+ - each model reply → token accumulation (on_model_call)
8
+ - each tool call → tool governance (on_tool_call)
9
+ - run complete → RECORD + TRACE (post_invoke)
10
+ - failure → on_error
11
+
12
+ Two integration styles:
13
+ 1. `AigpMafGovernance.run(agent, prompt, ...)` — wrap a run explicitly.
14
+ 2. `AigpMafMiddleware` — register as MAF agent/function middleware for automatic coverage.
15
+
16
+ The framework object is duck-typed (usage read from the response), so this adapter does not
17
+ import MAF directly and works across MAF point releases.
18
+ """
19
+
20
+ import asyncio
21
+ import logging
22
+ import time
23
+
24
+ from aigp_agent_core import AgentGovernance
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ def _extract_usage(response) -> dict:
30
+ """Best-effort token usage from a MAF run result / model response."""
31
+ usage = getattr(response, "usage", None) or getattr(response, "usage_details", None)
32
+ if usage is None and isinstance(response, dict):
33
+ usage = response.get("usage")
34
+ if usage is None:
35
+ return {}
36
+ # MAF/OpenAI-style attributes or dict keys
37
+ def _get(o, *names):
38
+ for n in names:
39
+ v = getattr(o, n, None) if not isinstance(o, dict) else o.get(n)
40
+ if v is not None:
41
+ return v
42
+ return 0
43
+ return {
44
+ "input_tokens": _get(usage, "input_token_count", "prompt_tokens", "input_tokens"),
45
+ "output_tokens": _get(usage, "output_token_count", "completion_tokens", "output_tokens"),
46
+ }
47
+
48
+
49
+ class AigpMafGovernance:
50
+ """Govern Microsoft Agent Framework agent runs with AIGP."""
51
+
52
+ def __init__(self, gov_url: str, app_id: str, hmac_secret: str, **kwargs):
53
+ self._gov = AgentGovernance(gov_url, app_id, hmac_secret, **kwargs)
54
+ self._app_id = app_id
55
+
56
+ async def run(self, agent, prompt, *, agent_name: str = "", model_id: str = "",
57
+ user_id: str = "", **run_kwargs):
58
+ """Governed MAF agent run. CHECK before, RECORD/TRACE after.
59
+
60
+ Args:
61
+ agent: a MAF agent exposing an async ``run(prompt, **kwargs)``.
62
+ prompt: the input passed to the agent.
63
+ agent_name: use-case label (defaults to the agent's name or app_id).
64
+ model_id: model identifier for the RECORD (best-effort if omitted).
65
+ """
66
+ name = agent_name or getattr(agent, "name", None) or self._app_id
67
+ model = model_id or getattr(agent, "model_id", "") or getattr(agent, "model", "")
68
+ self._gov.pre_invoke(name, str(model), user_id)
69
+ try:
70
+ result = await agent.run(prompt, **run_kwargs)
71
+ self._gov.on_model_call(usage=_extract_usage(result))
72
+ await self._gov.post_invoke()
73
+ return result
74
+ except Exception as e:
75
+ await self._gov.on_error(e)
76
+ raise
77
+
78
+ async def on_tool_call(self, tool_name: str, params: dict | None = None, duration_ms: int = 0):
79
+ """Report a MAF function-tool invocation for governance."""
80
+ await self._gov.on_tool_call(tool_name, params=params, duration_ms=duration_ms)
81
+
82
+ def middleware(self) -> "AigpMafMiddleware":
83
+ """Return a MAF-compatible middleware bound to this governance instance."""
84
+ return AigpMafMiddleware(self)
85
+
86
+
87
+ class AigpMafMiddleware:
88
+ """MAF agent/function middleware that governs each run.
89
+
90
+ MAF middleware are callables invoked around agent runs and function calls with a `context`
91
+ and a `next` continuation. This class supports both by duck-typing the context.
92
+ """
93
+
94
+ def __init__(self, governance: AigpMafGovernance):
95
+ self._g = governance
96
+
97
+ async def __call__(self, context, next): # noqa: A002 - MAF's middleware signature
98
+ agent = getattr(context, "agent", None)
99
+ name = getattr(agent, "name", None) or getattr(context, "agent_name", "") or self._g._app_id
100
+ model = getattr(agent, "model_id", "") or getattr(agent, "model", "")
101
+ self._g._gov.pre_invoke(name, str(model), getattr(context, "user_id", ""))
102
+ try:
103
+ result = await next(context)
104
+ self._g._gov.on_model_call(usage=_extract_usage(result))
105
+ await self._g._gov.post_invoke()
106
+ return result
107
+ except Exception as e:
108
+ await self._g._gov.on_error(e)
109
+ raise
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.5
2
+ Name: maigp-microsoft-agent-framework
3
+ Version: 1.0.0
4
+ Summary: AIGP governance adapter for Microsoft Agent Framework (MAF) — the converged Semantic Kernel + AutoGen SDK (GA 2026-04-03)
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: maigp-agent-core>=1.0.0
7
+ Provides-Extra: dev
8
+ Requires-Dist: pytest; extra == 'dev'
9
+ Requires-Dist: pytest-asyncio; extra == 'dev'
@@ -0,0 +1,5 @@
1
+ aigp_microsoft_agent_framework/__init__.py,sha256=IFXihXhtgOi1zOmOI4gLPpHHu9bpa12B9v844LZrXqo,1223
2
+ aigp_microsoft_agent_framework/handler.py,sha256=QOhZEaVKeiesvlnEEZO-sIgcM28Pf75raWnV2fb6ql8,4516
3
+ maigp_microsoft_agent_framework-1.0.0.dist-info/METADATA,sha256=wc_59cMM7NWrdPmhjhmhCTJLwfOCHJ7OT1SJ0f9dmo8,375
4
+ maigp_microsoft_agent_framework-1.0.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
5
+ maigp_microsoft_agent_framework-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any