Integrate custom tools into your agent | AI-103 | Episode 8
AI agents become much more powerful when they can act on external systems, not just generate answers. Custom tools let a Foundry agent use application logic, databases, APIs, calculations, and workflows.
The Core Tool-Calling Pattern
Prompt → Agent → function_call → App executes tool → Result → Agent → Answer
A custom function tool has a name, description, and parameters. The agent uses these definitions to determine when a function is needed and what arguments to provide.
# 1. Create the agent
agent = project_client.agents.create_version(...)
# 2. Ask the agent
response = openai_client.responses.create(
conversation=conversation.id,
input="What's the weather in Zurich?",
extra_body={"agent": agent}
)
# 3. Check whether the agent wants to use a function
for item in response.output:
if item.type == "function_call":
# YOUR application executes the function
result = call_function(item.name, item.arguments)
# Return the result to the agent
send_function_result(item.call_id, result)
Key concept: the LLM does not execute your local function. It returns a function_call containing the requested function and arguments. Your application dispatches and executes it, then returns the result so the agent can continue reasoning.
Choose the Right Tool
| Need | Use |
|---|---|
| Local application code | Custom function |
| REST API described with OpenAPI | OpenAPI tool |
| Remote/serverless compute | Azure Functions |
| Low-code workflow | Logic Apps |
Remember
Agent = decides what to call → Application = executes it → Agent = uses the result
One prompt can trigger multiple function calls, allowing an agent to combine several operations before generating its final response.
Comments