Function Calls (Legacy)
This pattern uses the function_call_request and function_call_response fields which are deprecated. Modern agents use Content Parts instead — the server executes tools and streams status updates, removing the need for client-side execution.
This guide is preserved for integrations that still use older agents with the verbose_qa_with_dynamic_retrieval pattern.
Overview
Some older agents suggest a function call request that needs to be executed by the API client. The flow is:
- The user asks a question.
- The agent realizes it needs additional context and returns a
function_call_requestinstead of an answer. - The client executes the suggested function (e.g., a search) and sends the result back to the API.
- The agent uses the new context to answer the original question.
Example: Agent-Suggested Search
The verbose_qa_with_dynamic_retrieval agent can suggest a search function call when the current context doesn't contain relevant information for a follow-up question.
import json
import os
import requests
import sseclient
TENANT = "zetaalpha"
CHAT_STREAMING_ENDPOINT = (
f"https://api.zeta-alpha.com/v0/service/chat/stream?tenant={TENANT}"
)
headers = {
"accept": "text/event-stream",
"Content-Type": "application/json",
"X-Auth": os.getenv("ZETA_ALPHA_API_KEY"),
}
response = requests.post(
CHAT_STREAMING_ENDPOINT,
headers=headers,
json={
"conversation_context": {
"document_context": {
"document_ids": [
"73effa5a188b69d32b5889a5ed564db5b66aeeb6_0",
"6277484c482c12e80166b3388ef8069b088dfcb6_0",
"6c42c17b131d886f0ccf4897d055e42580574240_0",
"df40f22694ea7515ef8cd321d877e54c30d336ca_0",
"bea6364917260019f43a72a3906d9a417029b9be_0",
],
"retrieval_unit": "document",
}
},
"conversation": [
{
"sender": "user",
"content": "What is BERT?",
},
{
"sender": "bot",
"content": "BERT stands for Bidirectional Encoder Representations from Transformers...",
"evidences": [
{
"document_hit_url": "/documents/document/list?tenant=zetaalpha&property_name=id&property_values=df40f22694ea7515ef8cd321d877e54c30d336ca_0",
"text_extract": "What is BERT? <b>In 2018 Google developed a transformer-based NLP pretraining model called BERT.</b>",
"anchor_text": "<sup>4</sup>",
}
],
},
{
"sender": "user",
"content": "What is CLIP?",
},
],
"agent_identifier": "verbose_qa_with_dynamic_retrieval",
},
stream=True,
)
response.raise_for_status()
client = sseclient.SSEClient(response)
for event in client.events():
streamed_data = json.loads(event.data)
# Check if the agent requests a function call
if streamed_data.get("function_call_request"):
print(f"Function call requested: {streamed_data['function_call_request']}")
Sample output:
Function call requested: {
"name": "document_search",
"params": {
"search_engine": "zeta_alpha",
"retrieval_method": "mixed",
"query_string": "What is CLIP?",
"document_type": ["document"]
}
}
Handling the Function Call
When you receive a function_call_request:
- Execute the suggested function (e.g., call the Search API with the provided params).
- Pass the results back as new context in a follow-up request.
- Include the function call exchange in the conversation history.
The function_call_request object contains:
| Field | Description |
|---|---|
name | The function to execute (e.g., "document_search") |
params | Parameters for the function call |
Migration to Tool Content Parts
If you are building a new integration, use agents that support Content Parts instead. The modern pattern:
- The server executes tools automatically (no client action needed)
- Tool status is streamed in
content_partswithtype: "tool" - Multiple tools can execute concurrently
- You only need to render the progress — not implement the function