Skip to content

Commit 9b46eb9

Browse files
committed
Refactor ToolClient to handle optional schema properties and required fields
1 parent 82e5ce9 commit 9b46eb9

File tree

2 files changed

+21
-21
lines changed
  • sdk/agentserver
    • azure-ai-agentserver-agentframework/azure/ai/agentserver/agentframework
    • azure-ai-agentserver-langgraph/azure/ai/agentserver/langgraph

2 files changed

+21
-21
lines changed

sdk/agentserver/azure-ai-agentserver-agentframework/azure/ai/agentserver/agentframework/tool_client.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,32 @@
1616
# pylint: disable=client-accepts-api-version-keyword,missing-client-constructor-parameter-credential,missing-client-constructor-parameter-kwargs
1717
class ToolClient:
1818
"""Client that integrates AzureAIToolClient with Agent Framework.
19-
19+
2020
This class provides methods to list tools from AzureAIToolClient and invoke them
2121
in a format compatible with Agent Framework agents.
22-
22+
2323
:param tool_client: The AzureAIToolClient instance to use for tool operations.
2424
:type tool_client: ~azure.ai.agentserver.core.client.tools.aio.AzureAIToolClient
25-
25+
2626
.. admonition:: Example:
27-
27+
2828
.. code-block:: python
29-
29+
3030
from azure.ai.agentserver.core.client.tools.aio import AzureAIToolClient
3131
from azure.ai.agentserver.agentframework import ToolClient
3232
from azure.identity.aio import DefaultAzureCredential
33-
33+
3434
async with DefaultAzureCredential() as credential:
3535
tool_client = AzureAIToolClient(
3636
endpoint="https://<your-project-endpoint>",
3737
credential=credential
3838
)
39-
39+
4040
client = ToolClient(tool_client)
41-
41+
4242
# List tools as Agent Framework tool definitions
4343
tools = await client.list_tools()
44-
44+
4545
# Invoke a tool directly
4646
result = await client.invoke_tool(
4747
tool_name="my_tool",
@@ -53,7 +53,7 @@ class ToolClient:
5353

5454
def __init__(self, tool_client: "AzureAIToolClient") -> None:
5555
"""Initialize the ToolClient.
56-
56+
5757
:param tool_client: The AzureAIToolClient instance to use for tool operations.
5858
:type tool_client: ~azure.ai.agentserver.core.client.tools.aio.AzureAIToolClient
5959
"""
@@ -62,19 +62,19 @@ def __init__(self, tool_client: "AzureAIToolClient") -> None:
6262

6363
async def list_tools(self) -> List[AIFunction]:
6464
"""List all available tools as Agent Framework tool definitions.
65-
65+
6666
Retrieves tools from AzureAIToolClient and returns them in a format
6767
compatible with Agent Framework.
68-
68+
6969
:return: List of tool definitions.
7070
:rtype: List[AIFunction]
7171
:raises ~azure.core.exceptions.HttpResponseError:
7272
Raised for HTTP communication failures.
73-
73+
7474
.. admonition:: Example:
75-
75+
7676
.. code-block:: python
77-
77+
7878
client = ToolClient(tool_client)
7979
tools = await client.list_tools()
8080
"""
@@ -94,7 +94,7 @@ async def list_tools(self) -> List[AIFunction]:
9494

9595
def _convert_to_agent_framework_tool(self, azure_tool: "FoundryTool") -> AIFunction:
9696
"""Convert an AzureAITool to an Agent Framework AI Function
97-
97+
9898
:param azure_tool: The AzureAITool to convert.
9999
:type azure_tool: ~azure.ai.agentserver.core.client.tools.aio.FoundryTool
100100
:return: An AI Function Tool.
@@ -104,8 +104,8 @@ def _convert_to_agent_framework_tool(self, azure_tool: "FoundryTool") -> AIFunct
104104
input_schema = azure_tool.input_schema or {}
105105

106106
# Create a Pydantic model from the input schema
107-
properties = input_schema.get("properties", {})
108-
required_fields = set(input_schema.get("required", []))
107+
properties = input_schema.get("properties") or {}
108+
required_fields = set(input_schema.get("required") or [])
109109

110110
# Build field definitions for the Pydantic model
111111
field_definitions: Dict[str, Any] = {}
@@ -146,7 +146,7 @@ async def tool_func(**kwargs: Any) -> Any:
146146

147147
def _json_schema_type_to_python(self, json_type: str) -> type:
148148
"""Convert JSON schema type to Python type.
149-
149+
150150
:param json_type: The JSON schema type string.
151151
:type json_type: str
152152
:return: The corresponding Python type.

sdk/agentserver/azure-ai-agentserver-langgraph/azure/ai/agentserver/langgraph/tool_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ def _create_pydantic_model(
159159
:rtype: type[BaseModel]
160160
"""
161161
# Get properties from schema
162-
properties = schema.get("properties", {})
163-
required_fields = schema.get("required", [])
162+
properties = schema.get("properties") or {}
163+
required_fields = schema.get("required") or []
164164

165165
# Build field definitions for Pydantic model
166166
field_definitions = {}

0 commit comments

Comments
 (0)