chatomon.connectors.maf
¶
Build an atom into a native Microsoft Agent Framework agent.
Install with pip install 'chatomon[maf]' or chatomon[maf-foundry].
Classes:
| Name | Description |
|---|---|
MAFConnector |
Build an atom into a native |
MAFFoundryConnector |
Build an atom into a native |
MAFConnector
¶
MAFConnector(
client: Any,
*,
resolve_client: Callable[[str], Any] | None = None,
**agent_kwargs: Any
)
Build an atom into a native agent_framework.Agent.
The client can be any MAF chat client that implements ChatMiddlewareLayer,
including FoundryChatClient. Provider clients such as OpenAIChatClient
need their own MAF distribution in addition to chatomon[maf]. The
connector places chatomon middleware
outside agent middleware supplied by the caller. Local AgentSession history
is used with store=False; pass a session from agent.create_session() to
keep turns together. MAF's native run API is asynchronous.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Any
|
The nucleus MAF chat client. |
required |
resolve_client
|
Callable[[str], Any] | None
|
Maps a |
None
|
**agent_kwargs
|
Any
|
Forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
ChatomonConfigError
|
If an argument conflicts with atom identity, enables remote conversation continuity, or bypasses the chat middleware. |
Examples:
import asyncio
import os
from agent_framework.openai import OpenAIChatClient
from openai import AsyncOpenAI
from chatomon import Atom
from chatomon.connectors.maf import MAFConnector
async def main() -> None:
async with AsyncOpenAI() as provider:
client = OpenAIChatClient(
model=os.environ["MAF_MODEL"], async_client=provider
)
agent = Atom(
name="assistant",
instructions="Be concise.",
connector=MAFConnector(client),
).build()
reply = await agent.run("Hello", session=agent.create_session())
print(reply.text)
asyncio.run(main())
Methods:
| Name | Description |
|---|---|
build |
Build the native MAF agent with chatomon's middleware installed. |
generate_structured |
Run a structured judge call with a resolved MAF chat client. |
Source code in src/chatomon/connectors/maf/_core.py
77 78 79 80 81 82 83 84 85 86 | |
build
¶
Build the native MAF agent with chatomon's middleware installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atom
|
Atom[Agent[Any]]
|
The validated atom. |
required |
engine
|
Engine
|
The engine that runs the atom's orbitals. |
required |
Returns:
| Type | Description |
|---|---|
Agent[Any]
|
A native MAF agent. |
Raises:
| Type | Description |
|---|---|
ChatomonConfigError
|
If the client cannot run chat middleware or preconfigured client middleware could rewrite checked output. |
Source code in src/chatomon/connectors/maf/_core.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
generate_structured
async
¶
Run a structured judge call with a resolved MAF chat client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The judge model identifier. |
required |
system
|
str
|
Judge instructions. |
required |
prompt
|
str
|
Judge input. |
required |
schema
|
type[ModelT]
|
Required Pydantic result type. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
The validated judge result. |
Raises:
| Type | Description |
|---|---|
ChatomonConfigError
|
If |
ValueError
|
If the judge returned no structured answer. |
Source code in src/chatomon/connectors/maf/_core.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
MAFFoundryConnector
¶
Bases: Connector['FoundryAgent']
Build an atom into a native agent_framework.foundry.FoundryAgent.
This connector attaches to an agent already configured in Foundry. Input
and output orbitals run around its local MAF session. Atom instructions and
knowledge are sent as a developer message because Foundry rejects the
request-level instructions field when an agent is specified. Rejected
drafts are replaced or regenerated before entering local history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolve_client
|
Callable[[str], Any] | None
|
Maps a |
None
|
**foundry_kwargs
|
Any
|
Forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
ChatomonConfigError
|
If an argument conflicts with atom identity or enables remote conversation continuity. |
MissingExtraError
|
If |
Examples:
import asyncio
import os
from azure.identity.aio import DefaultAzureCredential
from chatomon import Atom
from chatomon.connectors.maf import MAFFoundryConnector
async def main() -> None:
async with DefaultAzureCredential() as credential:
agent = Atom(
name="assistant",
instructions="Be concise.",
connector=MAFFoundryConnector(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
agent_name=os.environ["FOUNDRY_AGENT_NAME"],
agent_version=os.environ["FOUNDRY_AGENT_VERSION"],
credential=credential,
),
).build()
try:
reply = await agent.run("Hello", session=agent.create_session())
print(reply.text)
finally:
await agent.client.close()
asyncio.run(main())
Methods:
| Name | Description |
|---|---|
build |
Build a native Foundry agent with checks and local history. |
generate_structured |
Run a structured judge call with a resolved MAF chat client. |
Source code in src/chatomon/connectors/maf/_foundry.py
79 80 81 82 83 84 85 86 87 88 89 90 91 | |
build
¶
Build a native Foundry agent with checks and local history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atom
|
Atom[FoundryAgent]
|
The validated atom. |
required |
engine
|
Engine
|
The engine that runs the atom's orbitals. |
required |
Returns:
| Type | Description |
|---|---|
FoundryAgent
|
A native Foundry agent. |
Raises:
| Type | Description |
|---|---|
ChatomonConfigError
|
If a custom client type is supplied. |
MissingExtraError
|
If the Foundry extra is not installed. |
Source code in src/chatomon/connectors/maf/_foundry.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
generate_structured
async
¶
Run a structured judge call with a resolved MAF chat client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The judge model identifier. |
required |
system
|
str
|
Judge instructions. |
required |
prompt
|
str
|
Judge input. |
required |
schema
|
type[ModelT]
|
Required Pydantic result type. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
The validated judge result. |
Raises:
| Type | Description |
|---|---|
ChatomonConfigError
|
If |
ValueError
|
If the judge returned no structured answer. |
Source code in src/chatomon/connectors/maf/_foundry.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |