mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING]: removed display_name, renamed context_providers, middleware and AggregateContextProvider (#3139)
* removed display_name, renamed context_providers, middleware and AggregateContextProvider * fixes * fixed test * testfix * removed mistakenly put back test * updated new test * rename middlewares to middleware * middleware fixes
This commit is contained in:
committed by
GitHub
Unverified
parent
ef44fb4960
commit
203fb7b1c4
@@ -202,7 +202,7 @@ async def main() -> None:
|
||||
print(f"User: {query}")
|
||||
result = await agent.run(
|
||||
query,
|
||||
middleware=HighPriorityMiddleware(), # Run-level middleware
|
||||
middleware=[HighPriorityMiddleware()], # Run-level middleware
|
||||
)
|
||||
print(f"Agent: {result.text if result.text else 'No response'}")
|
||||
print()
|
||||
|
||||
@@ -146,7 +146,7 @@ async def class_based_chat_middleware() -> None:
|
||||
name="EnhancedChatAgent",
|
||||
instructions="You are a helpful AI assistant.",
|
||||
# Register class-based middleware at agent level (applies to all runs)
|
||||
middleware=InputObserverMiddleware(),
|
||||
middleware=[InputObserverMiddleware()],
|
||||
tools=get_weather,
|
||||
) as agent,
|
||||
):
|
||||
@@ -168,7 +168,7 @@ async def function_based_chat_middleware() -> None:
|
||||
name="FunctionMiddlewareAgent",
|
||||
instructions="You are a helpful AI assistant.",
|
||||
# Register function-based middleware at agent level
|
||||
middleware=security_and_override_middleware,
|
||||
middleware=[security_and_override_middleware],
|
||||
) as agent,
|
||||
):
|
||||
# Scenario with normal query
|
||||
@@ -226,7 +226,7 @@ async def run_level_middleware() -> None:
|
||||
print(f"User: {query}")
|
||||
result = await agent.run(
|
||||
query,
|
||||
middleware=security_and_override_middleware,
|
||||
middleware=[security_and_override_middleware],
|
||||
)
|
||||
print(f"Response: {result.text if result.text else 'No response'}")
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ async def main() -> None:
|
||||
name="DataAgent",
|
||||
instructions="You are a helpful data assistant. Use the data service tool to fetch information for users.",
|
||||
tools=unstable_data_service,
|
||||
middleware=exception_handling_middleware,
|
||||
middleware=[exception_handling_middleware],
|
||||
) as agent,
|
||||
):
|
||||
query = "Get user statistics"
|
||||
|
||||
@@ -114,7 +114,7 @@ async def pre_termination_middleware() -> None:
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather assistant.",
|
||||
tools=get_weather,
|
||||
middleware=PreTerminationMiddleware(blocked_words=["bad", "inappropriate"]),
|
||||
middleware=[PreTerminationMiddleware(blocked_words=["bad", "inappropriate"])],
|
||||
) as agent,
|
||||
):
|
||||
# Test with normal query
|
||||
@@ -141,7 +141,7 @@ async def post_termination_middleware() -> None:
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather assistant.",
|
||||
tools=get_weather,
|
||||
middleware=PostTerminationMiddleware(max_responses=1),
|
||||
middleware=[PostTerminationMiddleware(max_responses=1)],
|
||||
) as agent,
|
||||
):
|
||||
# First run (should work)
|
||||
|
||||
@@ -87,7 +87,7 @@ async def main() -> None:
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather assistant. Use the weather tool to get current conditions.",
|
||||
tools=get_weather,
|
||||
middleware=weather_override_middleware,
|
||||
middleware=[weather_override_middleware],
|
||||
) as agent,
|
||||
):
|
||||
# Non-streaming example
|
||||
|
||||
@@ -74,7 +74,7 @@ async def main() -> None:
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather assistant.",
|
||||
tools=get_weather,
|
||||
middleware=thread_tracking_middleware,
|
||||
middleware=[thread_tracking_middleware],
|
||||
# Configure agent with message store factory to persist conversation history
|
||||
chat_message_store_factory=ChatMessageStore,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user