mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] changed AIFunction to FunctionTool and @ai_function to @tool (#3413)
* changed AIFunction to FunctionTool and @ai_function to @tool * test and mypy fixes * mypy fix * switch function tool to always_require * fix noop * fix github copilot imports * test fixes * fix ollama test * fixes for tests * fix tests * reverted change to always_require and extended timeout * fix test
This commit is contained in:
committed by
GitHub
Unverified
parent
15b43f2abe
commit
a7d924a7d2
@@ -2,22 +2,13 @@
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from collections.abc import Sequence
|
||||
|
||||
from agent_framework import (
|
||||
AgentResponse,
|
||||
ChatAgent,
|
||||
FunctionCallContent,
|
||||
FunctionResultContent,
|
||||
Role,
|
||||
TextContent,
|
||||
ai_function,
|
||||
)
|
||||
from agent_framework import ChatAgent, tool
|
||||
|
||||
from agent_framework_bedrock import BedrockChatClient
|
||||
|
||||
|
||||
@ai_function
|
||||
@tool(approval_mode="never_require")
|
||||
def get_weather(city: str) -> dict[str, str]:
|
||||
"""Return a mock forecast for the requested city."""
|
||||
normalized = city.strip() or "New York"
|
||||
@@ -36,27 +27,18 @@ async def main() -> None:
|
||||
|
||||
response = await agent.run("Use the weather tool to check the forecast for new york.")
|
||||
logging.info("\nAssistant reply:", response.text or "<no text returned>")
|
||||
_log_response(response)
|
||||
|
||||
|
||||
def _log_response(response: AgentResponse) -> None:
|
||||
logging.info("\nConversation transcript:")
|
||||
for idx, message in enumerate(response.messages, start=1):
|
||||
tag = f"{idx}. {message.role.value if isinstance(message.role, Role) else message.role}"
|
||||
_log_contents(tag, message.contents)
|
||||
|
||||
|
||||
def _log_contents(tag: str, contents: Sequence[object]) -> None:
|
||||
logging.info(f"[{tag}] {len(contents)} content blocks")
|
||||
for idx, content in enumerate(contents, start=1):
|
||||
if isinstance(content, TextContent):
|
||||
logging.info(f" {idx}. text -> {content.text}")
|
||||
elif isinstance(content, FunctionCallContent):
|
||||
logging.info(f" {idx}. tool_call ({content.name}) -> {content.arguments}")
|
||||
elif isinstance(content, FunctionResultContent):
|
||||
logging.info(f" {idx}. tool_result ({content.call_id}) -> {content.result}")
|
||||
else: # pragma: no cover - defensive
|
||||
logging.info(f" {idx}. {content.type}")
|
||||
for message in response.messages:
|
||||
for idx, content in enumerate(message.contents, start=1):
|
||||
match content.type:
|
||||
case "text":
|
||||
logging.info(f" {idx}. text -> {content.text}")
|
||||
case "function_call":
|
||||
logging.info(f" {idx}. function_call ({content.name}) -> {content.arguments}")
|
||||
case "function_result":
|
||||
logging.info(f" {idx}. function_result ({content.call_id}) -> {content.result}")
|
||||
case _:
|
||||
logging.info(f" {idx}. {content.type}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user