Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/packages/core/agent_framework/_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

evals = FoundryEvals(project_client=client, model="gpt-4o")
results = await evaluate_agent(agent=agent, queries=["Hello"], evaluators=evals)
results.raise_for_status()
for result in results:
result.raise_for_status()

Local evaluator example:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naveen Chatlapalli (@1aifanatic), this local example has another pre-existing problem: it calls tool_called_check without importing it, so copying it raises NameError before evaluation starts. Could you add tool_called_check to the agent_framework import here and in the LocalEvaluator basic-usage example, which has the same omission?


Expand Down
26 changes: 19 additions & 7 deletions python/packages/core/agent_framework/_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ class ChatContext:

class TokenCounterMiddleware(ChatMiddleware):
async def process(self, context: ChatContext, call_next):
print(f"Chat client: {context.chat_client.__class__.__name__}")
print(f"Chat client: {context.client.__class__.__name__}")
print(f"Messages: {len(context.messages)}")
print(f"Model: {context.options.get('model')}")

Expand Down Expand Up @@ -859,19 +859,31 @@ class AgentMiddleware(ABC):
Examples:
.. code-block:: python

from agent_framework import AgentMiddleware, AgentContext, Agent
from agent_framework import (
Agent,
AgentContext,
AgentMiddleware,
MiddlewareFailure,
MiddlewareTermination,
)


class RetryMiddleware(AgentMiddleware):
def __init__(self, max_retries: int = 3):
self.max_retries = max_retries

async def process(self, context: AgentContext, call_next):
for attempt in range(self.max_retries):
await call_next()
if context.result and not context.result.is_error:
break
print(f"Retry {attempt + 1}/{self.max_retries}")
for attempt in range(1, self.max_retries + 1):
try:
await call_next()
return
except (MiddlewareFailure, MiddlewareTermination):
# Abort and stop signals must reach the caller unchanged.
raise
except Exception:
Comment thread
eavanvalkenburg marked this conversation as resolved.
if attempt == self.max_retries:
raise
print(f"Retry {attempt}/{self.max_retries}")


# Use with an agent
Expand Down
6 changes: 3 additions & 3 deletions python/packages/core/agent_framework/observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ class ObservabilitySettings:
Examples:
.. code-block:: python

from agent_framework import ObservabilitySettings
from agent_framework.observability import ObservabilitySettings

# Using environment variables
# Instrumentation is enabled by default; set ENABLE_INSTRUMENTATION=false to disable.
Expand Down Expand Up @@ -1397,7 +1397,7 @@ def get_tracer(
Examples:
.. code-block:: python

from agent_framework import get_tracer
from agent_framework.observability import get_tracer

# Get default tracer
tracer = get_tracer()
Expand Down Expand Up @@ -1446,7 +1446,7 @@ def get_meter(
Examples:
.. code-block:: python

from agent_framework import get_meter
from agent_framework.observability import get_meter

# Get default meter
meter = get_meter()
Expand Down
11 changes: 6 additions & 5 deletions python/packages/core/agent_framework/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,8 @@ class LabelTrackingFunctionMiddleware(FunctionMiddleware, _SecurityScopeBinding)
Examples:
.. code-block:: python

from agent_framework import Agent, LabelTrackingFunctionMiddleware, tool
from agent_framework import Agent, tool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naveen Chatlapalli (@1aifanatic), the run call below was already broken before this PR: Agent.run leaves the OpenAI-style dictionary unchanged, and the OpenAI serializer then raises 'dict' object has no attribute 'role'. Could you import Message here and pass messages=[Message("user", ["What's the weather?"])], or simply use await agent.run("What's the weather?")?

from agent_framework.security import LabelTrackingFunctionMiddleware


@tool(additional_properties={"source_integrity": "trusted"})
Expand Down Expand Up @@ -4314,7 +4315,7 @@ def get_security_tools() -> list[FunctionTool]:
from agent_framework.security import get_security_tools

agent = Agent(
chat_client=client,
client=client,
instructions="You are a helpful assistant.",
tools=[my_tool, *get_security_tools()],
)
Expand Down Expand Up @@ -4467,10 +4468,10 @@ async def apply_mcp_security_labels(

async with MCPStdioTool(name="github", command="gh-mcp", args=["stdio"]) as mcp:
await apply_mcp_security_labels(mcp)
agent = ChatCompletionAgent(
chat_client=client,
agent = Agent(
client=client,
tools=[mcp],
context_providers=[SecureAgentConfig(chat_client=client)],
context_providers=[SecureAgentConfig(quarantine_chat_client=client)],
)
"""
if not getattr(mcp_tool, "is_connected", False):
Expand Down
Loading