Function Call Context

Provide function call context in conversation context when starting a new Voice Agent session.
Voice Agent

When starting a new conversation session with the Voice Agent, you can provide context about previous function calls using the agent.context parameter. This allows the agent to maintain awareness of past interactions and function executions, enabling more coherent and contextual conversations.

Overview

Function call history is particularly useful when:

  • Resuming a conversation from a previous session
  • Providing background context about actions already taken
  • Maintaining continuity in multi-session interactions
  • Allowing the agent to reference previous function results

Format

Function call history is included in the context using the History message type with a function_calls array. Each function call entry contains complete information about the execution, including arguments and results.

Function call history can be disabled by setting settings.flags.history to false in the agent configuration. History is enabled by default.

JSON
1{
2 "type": "Settings",
3 "settings": {
4 "flags": {
5 "history": true // true by default set to false to disable
6 }
7 },
8 "agent": {
9 "context": {
10 "messages": [
11 {
12 "type": "History",
13 "role": "user",
14 "content": "What's the weather like in New York?"
15 },
16 {
17 "type": "History",
18 "function_calls": [
19 {
20 "id": "fc_weather_12345",
21 "name": "get_weather",
22 "client_side": true,
23 "arguments": "{\"location\": \"New York\"}",
24 "response": "The current weather in New York is partly cloudy with a temperature of 295.15°K."
25 }
26 ]
27 },
28 {
29 "type": "History",
30 "role": "assistant",
31 "content": "The weather in New York is partly cloudy with a temperature of about 72°F (295.15°K)."
32 }
33 ]
34 },
35 "think": {
36 "provider": {
37 "type": "open_ai",
38 "model": "gpt-4o-mini"
39 },
40 "functions": [
41 {
42 "name": "get_weather",
43 "description": "Get the current weather for a specific location",
44 "parameters": {
45 "type": "object",
46 "properties": {
47 "location": {
48 "type": "string",
49 "description": "The city or location to get weather for"
50 }
51 },
52 "required": ["location"]
53 }
54 }
55 ]
56 }
57 }
58}

Function Call History Structure

Each function call in the history includes the following fields:

FieldTypeDescription
idStringA unique identifier for the function call
nameStringThe name of the function that was called
client_sideBooleanIndicates if the function was executed client-side or server-side
argumentsStringJSON string containing the arguments passed to the function
responseStringThe response/result returned by the function

Benefits of Function Call History

Including function call history in your agent context provides several advantages:

Continuity

The agent understands what functions were previously called and their results, enabling natural conversation flow across sessions.

Efficiency

The agent can reference previous function results instead of making redundant calls for the same information.

Context Awareness

The agent can make informed decisions based on the complete interaction history, including both conversations and actions taken.

Natural Interactions

Users can refer to previous actions (“like we did before”) and the agent will understand the context.

Multiple Function Calls

You can include multiple function calls in a single history entry or across multiple entries:

JSON
1{
2 "type": "History",
3 "function_calls": [
4 {
5 "id": "fc_weather_001",
6 "name": "get_weather",
7 "client_side": true,
8 "arguments": "{\"location\": \"New York\"}",
9 "response": "Partly cloudy, 72°F"
10 },
11 {
12 "id": "fc_weather_002",
13 "name": "get_weather",
14 "client_side": true,
15 "arguments": "{\"location\": \"Los Angeles\"}",
16 "response": "Sunny, 78°F"
17 }
18 ]
19}

Best Practices

Unique IDs

In most cases the LLM will assign ids. If the LLM does not assign ids, Deepgram will assign ids to the function calls.

Complete Information

Include both the arguments passed to the function and the complete response received.

Chronological Order

Maintain the chronological order of function calls and conversations in your history.

Relevant Context Only

Include only the function call history that’s relevant to the current conversation to avoid overwhelming the context.