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
@@ -19,7 +19,7 @@ from agent_framework import (
|
||||
Role,
|
||||
normalize_messages,
|
||||
)
|
||||
from agent_framework._tools import AIFunction, ToolProtocol
|
||||
from agent_framework._tools import FunctionTool, ToolProtocol
|
||||
from agent_framework._types import normalize_tools
|
||||
from agent_framework.exceptions import ServiceException, ServiceInitializationError
|
||||
from copilot import CopilotClient, CopilotSession
|
||||
@@ -417,8 +417,8 @@ class GithubCopilotAgent(BaseAgent, Generic[TOptions]):
|
||||
for tool in tools:
|
||||
if isinstance(tool, ToolProtocol):
|
||||
match tool:
|
||||
case AIFunction():
|
||||
copilot_tools.append(self._ai_function_to_copilot_tool(tool)) # type: ignore
|
||||
case FunctionTool():
|
||||
copilot_tools.append(self._tool_to_copilot_tool(tool)) # type: ignore
|
||||
case _:
|
||||
logger.debug(f"Unsupported tool type: {type(tool)}")
|
||||
elif isinstance(tool, CopilotTool):
|
||||
@@ -426,8 +426,8 @@ class GithubCopilotAgent(BaseAgent, Generic[TOptions]):
|
||||
|
||||
return copilot_tools
|
||||
|
||||
def _ai_function_to_copilot_tool(self, ai_func: AIFunction[Any, Any]) -> CopilotTool:
|
||||
"""Convert an AIFunction to a Copilot SDK tool."""
|
||||
def _tool_to_copilot_tool(self, ai_func: FunctionTool[Any, Any]) -> CopilotTool:
|
||||
"""Convert an FunctionTool to a Copilot SDK tool."""
|
||||
|
||||
async def handler(invocation: ToolInvocation) -> ToolResult:
|
||||
args = invocation.get("arguments", {})
|
||||
|
||||
@@ -7,7 +7,14 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from agent_framework import AgentResponse, AgentResponseUpdate, AgentThread, ChatMessage, Content, Role
|
||||
from agent_framework import (
|
||||
AgentResponse,
|
||||
AgentResponseUpdate,
|
||||
AgentThread,
|
||||
ChatMessage,
|
||||
Content,
|
||||
Role,
|
||||
)
|
||||
from agent_framework.exceptions import ServiceException
|
||||
from copilot.generated.session_events import Data, SessionEvent, SessionEventType
|
||||
|
||||
@@ -733,10 +740,10 @@ class TestGithubCopilotAgentToolConversion:
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that mixed tool types are handled correctly."""
|
||||
from agent_framework._tools import ai_function
|
||||
from agent_framework import tool
|
||||
from copilot.types import Tool as CopilotTool
|
||||
|
||||
@ai_function
|
||||
@tool(approval_mode="never_require")
|
||||
def my_function(arg: str) -> str:
|
||||
"""A function tool."""
|
||||
return arg
|
||||
@@ -754,7 +761,7 @@ class TestGithubCopilotAgentToolConversion:
|
||||
result = agent._prepare_tools([my_function, copilot_tool]) # type: ignore
|
||||
|
||||
assert len(result) == 2
|
||||
# First tool is converted AIFunction
|
||||
# First tool is converted FunctionTool
|
||||
assert result[0].name == "my_function"
|
||||
# Second tool is CopilotTool passthrough
|
||||
assert result[1] == copilot_tool
|
||||
|
||||
Reference in New Issue
Block a user