mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fixed AutoGen migration and tool samples (#4027)
* Fixed ollama_chat_client sample * Fixed ollama_chat_multimodal sample * Fixed function_tool_with_approval_and_sessions sample * Updated function_tool_with_session_injection sample * Small clean-up * Update 01_round_robin_group_chat.py * Update 02_selector_group_chat.py * Update 03_swarm.py * Update 03_assistant_agent_thread_and_stream.py * Update 04_agent_as_tool.py * Resolved comments
This commit is contained in:
committed by
GitHub
Unverified
parent
f9f630829a
commit
f087b864fb
@@ -17,7 +17,7 @@ the task in a round-robin fashion.
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentResponseUpdate
|
||||
from agent_framework import Message
|
||||
|
||||
|
||||
async def run_autogen() -> None:
|
||||
@@ -91,17 +91,12 @@ async def run_agent_framework() -> None:
|
||||
|
||||
# Run the workflow
|
||||
print("[Agent Framework] Sequential conversation:")
|
||||
current_executor = None
|
||||
async for event in workflow.run("Create a brief summary about electric vehicles", stream=True):
|
||||
if event.type == "output" and isinstance(event.data, AgentResponseUpdate):
|
||||
# Print executor name header when switching to a new agent
|
||||
if current_executor != event.executor_id:
|
||||
if current_executor is not None:
|
||||
print() # Newline after previous agent's message
|
||||
print(f"---------- {event.executor_id} ----------")
|
||||
current_executor = event.executor_id
|
||||
print(event.data.text, end="", flush=True)
|
||||
print() # Final newline after conversation
|
||||
if event.type == "output" and isinstance(event.data, list):
|
||||
for message in event.data:
|
||||
if isinstance(message, Message) and message.role == "assistant" and message.text:
|
||||
print(f"---------- {message.author_name} ----------")
|
||||
print(message.text)
|
||||
|
||||
|
||||
async def run_agent_framework_with_cycle() -> None:
|
||||
|
||||
@@ -17,7 +17,7 @@ which agent should speak next based on the conversation context.
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentResponseUpdate
|
||||
from agent_framework import Message
|
||||
|
||||
|
||||
async def run_autogen() -> None:
|
||||
@@ -106,18 +106,12 @@ async def run_agent_framework() -> None:
|
||||
|
||||
# Run with a question that requires expert selection
|
||||
print("[Agent Framework] Group chat conversation:")
|
||||
current_executor = None
|
||||
async for event in workflow.run("How do I connect to a PostgreSQL database using Python?", stream=True):
|
||||
if event.type == "output" and isinstance(event.data, AgentResponseUpdate):
|
||||
# Print executor name header when switching to a new agent
|
||||
if current_executor != event.executor_id:
|
||||
if current_executor is not None:
|
||||
print() # Newline after previous agent's message
|
||||
print(f"---------- {event.executor_id} ----------")
|
||||
current_executor = event.executor_id
|
||||
if event.data:
|
||||
print(event.data.text, end="", flush=True)
|
||||
print() # Final newline after conversation
|
||||
if event.type == "output" and isinstance(event.data, list):
|
||||
for message in event.data:
|
||||
if isinstance(message, Message) and message.role == "assistant" and message.text:
|
||||
print(f"---------- {message.author_name} ----------")
|
||||
print(message.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
||||
@@ -18,7 +18,7 @@ to other specialized agents based on the task requirements.
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentResponseUpdate, WorkflowEvent
|
||||
from orderedmultidict import Any
|
||||
from typing import Any
|
||||
|
||||
|
||||
async def run_autogen() -> None:
|
||||
@@ -197,7 +197,9 @@ async def run_agent_framework() -> None:
|
||||
print("---------- user ----------")
|
||||
print(user_response)
|
||||
|
||||
responses: dict[str, Any] = {req.request_id: user_response for req in pending_requests} # type: ignore
|
||||
responses: dict[str, Any] = {
|
||||
req.request_id: HandoffAgentUserRequest.create_response(user_response) for req in pending_requests
|
||||
} # type: ignore
|
||||
pending_requests = []
|
||||
current_executor = None
|
||||
stream_line_open = False
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ async def run_autogen() -> None:
|
||||
|
||||
print("\n[AutoGen] Streaming response:")
|
||||
# Stream response with Console for token streaming
|
||||
await Console(agent.run(task="Count from 1 to 5", stream=True))
|
||||
await Console(agent.run_stream(task="Count from 1 to 5"))
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
|
||||
@@ -53,7 +53,7 @@ async def run_autogen() -> None:
|
||||
|
||||
# Run coordinator with streaming - it will delegate to writer
|
||||
print("[AutoGen]")
|
||||
await Console(coordinator.run(task="Create a tagline for a coffee shop", stream=True))
|
||||
await Console(coordinator.run_stream(task="Create a tagline for a coffee shop"))
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
|
||||
Reference in New Issue
Block a user