Python: [BREAKING] Replace Hosted*Tool classes with tool methods (#3634)

* Replace Hosted*Tool classes with client static factory methods

* fixed failing test

* mypy fix

* mypy fix 2

* declarative mypy fix

* addressed comments

* ToolProtocol removal

* fixed test

* agents mypy fix

* fix failing tests

* mypy fix

* addressed comments

* fixed tests

* addressed comments + added factory method overrides for azureai v2 client

* mypy fix

* added kwargs to azureai tool methods

* fixed in test

* _sessions fix

* test fix
This commit is contained in:
Giles Odigwe
2026-02-10 16:04:27 -08:00
committed by GitHub
Unverified
parent d249473a6d
commit 7a88af0aef
133 changed files with 3018 additions and 2650 deletions
@@ -83,10 +83,9 @@ async def main() -> None:
HandoffBuilder(
name="autonomous_iteration_handoff",
participants=[coordinator, research_agent, summary_agent],
termination_condition=lambda conv: sum(
1 for msg in conv if msg.author_name == "coordinator" and msg.role == "assistant"
)
>= 5,
termination_condition=lambda conv: (
sum(1 for msg in conv if msg.author_name == "coordinator" and msg.role == "assistant") >= 5
),
)
.with_start_agent(coordinator)
.add_handoff(coordinator, [research_agent, summary_agent])
@@ -33,7 +33,6 @@ from typing import cast
from agent_framework import (
Agent,
AgentResponseUpdate,
HostedCodeInterpreterTool,
Message,
WorkflowEvent,
WorkflowRunState,
@@ -109,13 +108,16 @@ async def create_agents_v1(credential: AzureCliCredential) -> AsyncIterator[tupl
),
)
# Create code interpreter tool using instance method
code_interpreter_tool = client.get_code_interpreter_tool()
code_specialist = client.as_agent(
name="code_specialist",
instructions=(
"You are a Python code specialist. Use the code interpreter to execute Python code "
"and create files when requested. Always save files to /mnt/data/ directory."
),
tools=[HostedCodeInterpreterTool()],
tools=[code_interpreter_tool],
)
yield triage, code_specialist # type: ignore
@@ -139,6 +141,9 @@ async def create_agents_v2(credential: AzureCliCredential) -> AsyncIterator[tupl
instructions="You are a triage agent. Your ONLY job is to route requests to the appropriate specialist.",
)
# Create code interpreter tool using instance method
code_interpreter_tool = code_client.get_code_interpreter_tool()
code_specialist = code_client.as_agent(
name="CodeSpecialist",
instructions=(
@@ -147,7 +152,7 @@ async def create_agents_v2(credential: AzureCliCredential) -> AsyncIterator[tupl
"Always save files to /mnt/data/ directory. "
"Do NOT discuss handoffs or routing - just complete the coding task directly."
),
tools=[HostedCodeInterpreterTool()],
tools=[code_interpreter_tool],
)
yield triage, code_specialist
@@ -8,7 +8,6 @@ from typing import cast
from agent_framework import (
Agent,
AgentResponseUpdate,
HostedCodeInterpreterTool,
Message,
WorkflowEvent,
)
@@ -54,12 +53,16 @@ async def main() -> None:
client=OpenAIChatClient(model_id="gpt-4o-search-preview"),
)
# Create code interpreter tool using instance method
coder_client = OpenAIResponsesClient()
code_interpreter_tool = coder_client.get_code_interpreter_tool()
coder_agent = Agent(
name="CoderAgent",
description="A helpful assistant that writes and executes code to process and analyze data.",
instructions="You solve questions using code. Please provide detailed analysis and computation process.",
client=OpenAIResponsesClient(),
tools=HostedCodeInterpreterTool(),
client=coder_client,
tools=code_interpreter_tool,
)
# Create a manager agent for orchestration