The Augment Python SDK now supports function calling, allowing you to provide Python functions that the agent can invoke during execution. This enables the agent to interact with external systems, perform calculations, fetch data, and more.
Define Python functions with type hints and docstrings:
def get_weather(location: str, unit: str = "celsius") -> dict:
"""
Get the current weather for a location.
Args:
location: City name or coordinates
unit: Temperature unit (celsius or fahrenheit)
"""
# Your implementation
return {"temp": 22, "condition": "sunny"}from auggie_sdk import Auggie
agent = Auggie()
result = agent.run(
"What's the weather in San Francisco?",
return_type=dict,
functions=[get_weather]
)- Function schemas are added to the instruction prompt
- Agent receives instruction and can call functions as needed
- If agent calls a function, it returns:
<function-call> { "name": "get_weather", "arguments": {"location": "San Francisco", "unit": "celsius"} } </function-call> - SDK parses the function call and executes the function
- SDK sends results back to agent in the same conversation
- Agent continues with the response (can call more functions if needed)
- Final response is parsed according to
return_type
This all happens in the normal code path - function calling is integrated seamlessly.
For functions to work properly with the agent:
-
Type Hints: All parameters should have type hints
def my_func(param1: str, param2: int) -> dict:
-
Docstrings: Include parameter descriptions in docstring
""" Function description. Args: param1: Description of param1 param2: Description of param2 """
-
Return Type: Specify return type hint
def my_func(...) -> dict:
The schema generator supports:
- Basic types:
str,int,float,bool - Collections:
list,dict,List[T],Dict[K, V] - Optional types:
Optional[T] - Union types:
Union[T1, T2] - Any type:
Any
def add_numbers(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
result = agent.run(
"What is 15 + 27?",
return_type=int,
functions=[add_numbers]
)def multiply(a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
def divide(a: int, b: int) -> float:
"""Divide two numbers."""
return a / b
result = agent.run(
"Calculate (10 * 5) / 2",
return_type=float,
functions=[multiply, divide]
)def fetch_data(source: str) -> list:
"""Fetch data from a source."""
return [{"id": 1, "value": 100}, {"id": 2, "value": 200}]
def process_data(data: list) -> dict:
"""Process the fetched data."""
total = sum(item["value"] for item in data)
return {"count": len(data), "total": total}
result = agent.run(
"Fetch data from 'api' and process it",
return_type=dict,
functions=[fetch_data, process_data]
)If a function raises an exception, the error is caught and returned to the agent:
def failing_function(x: int) -> int:
"""A function that might fail."""
if x < 0:
raise ValueError("x must be positive")
return x * 2
# Agent will receive error message and can handle it
result = agent.run(
"Call failing_function with x=-5",
return_type=str,
functions=[failing_function]
)- Maximum Rounds: Function calling is limited to 5 rounds to prevent infinite loops
- Function Signature: Functions must be callable with keyword arguments
- Serialization: Function arguments and return values must be JSON-serializable
- No Nested Calls: Functions cannot call other provided functions directly
Run the tests:
# Install the SDK
pip install auggie-sdk
# Run the function calling example
cd examples/python-sdk
python3 function_calling_example.pyFunctions are converted to this schema format:
{
"name": "function_name",
"description": "Function description from docstring",
"parameters": {
"type": "object",
"properties": {
"param1": {
"type": "string",
"description": "Parameter description"
}
},
"required": ["param1"]
}
}The agent uses XML tags to indicate function calls:
<function-call>
{
"name": "function_name",
"arguments": {"param": "value"}
}
</function-call>Multiple function calls can be made in a single response.
Potential improvements:
- Support for async functions
- Streaming function results
- Function call history/logging
- Better error recovery
- Function call validation before execution
- Support for more complex type hints (TypedDict, Literal, etc.)