Skip to content

Commit ab6a2f3

Browse files
committed
feat: add support for agent context history
1 parent 76f9653 commit ab6a2f3

File tree

6 files changed

+406
-1
lines changed

6 files changed

+406
-1
lines changed

src/lib/types/AgentLiveSchema.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ type SpeakProvider = {
88
};
99
};
1010

11+
import type { HistoryConversationText } from "./HistoryConversationText";
12+
import type { HistoryFunctionCall } from "./HistoryFunctionCall";
13+
1114
/**
1215
* @see https://developers.deepgram.com/docs/configure-voice-agent
1316
*/
@@ -17,6 +20,19 @@ interface AgentLiveSchema extends Record<string, unknown> {
1720
* @default false
1821
*/
1922
experimental?: boolean;
23+
24+
/**
25+
* Configuration flags for agent features
26+
*/
27+
flags?: {
28+
/**
29+
* @see https://developers.deepgram.com/docs/configure-voice-agent#agentcontext
30+
* Enable or disable history message reporting
31+
* @default true
32+
*/
33+
history?: boolean;
34+
};
35+
2036
audio: {
2137
input?: {
2238
/**
@@ -47,6 +63,17 @@ interface AgentLiveSchema extends Record<string, unknown> {
4763
* @default "en"
4864
*/
4965
language?: string;
66+
67+
/**
68+
* Conversation context including the history of messages and function calls
69+
*/
70+
context?: {
71+
/**
72+
* Conversation history as a list of messages and function calls
73+
*/
74+
messages?: (HistoryConversationText | HistoryFunctionCall)[];
75+
};
76+
5077
listen?: {
5178
provider: Provider;
5279
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* History conversation text message schema for agent context
3+
* @see API specification for agent context history
4+
*/
5+
export interface HistoryConversationText {
6+
/**
7+
* Message type identifier for conversation text
8+
*/
9+
type: "History";
10+
11+
/**
12+
* Identifies who spoke the statement
13+
*/
14+
role: "user" | "assistant";
15+
16+
/**
17+
* The actual statement that was spoken
18+
*/
19+
content: string;
20+
}

src/lib/types/HistoryFunctionCall.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* History function call message schema for agent context
3+
* @see API specification for agent context history
4+
*/
5+
export interface HistoryFunctionCall {
6+
/**
7+
* Message type identifier for function calls
8+
*/
9+
type: "History";
10+
11+
/**
12+
* List of function call objects
13+
*/
14+
function_calls: {
15+
/**
16+
* Unique identifier for the function call
17+
*/
18+
id: string;
19+
20+
/**
21+
* Name of the function called
22+
*/
23+
name: string;
24+
25+
/**
26+
* Indicates if the call was client-side or server-side
27+
*/
28+
client_side: boolean;
29+
30+
/**
31+
* Arguments passed to the function
32+
*/
33+
arguments: string;
34+
35+
/**
36+
* Response from the function call
37+
*/
38+
response: string;
39+
}[];
40+
}

src/lib/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export * from "./GetProjectUsageSummarySchema";
2828
export * from "./GetTokenDetailsResponse";
2929
export * from "./GrantTokenResponse";
3030
export * from "./GrantTokenSchema";
31+
export * from "./HistoryConversationText";
32+
export * from "./HistoryFunctionCall";
3133
export * from "./ListOnPremCredentialsResponse";
3234
export * from "./LiveConfigOptions";
3335
export * from "./LiveMetadataEvent";

src/packages/AgentLiveClient.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { DEFAULT_AGENT_URL } from "../lib/constants";
22
import { AgentEvents } from "../lib/enums/AgentEvents";
3-
import type { AgentLiveSchema, DeepgramClientOptions, FunctionCallResponse } from "../lib/types";
3+
import type {
4+
AgentLiveSchema,
5+
DeepgramClientOptions,
6+
FunctionCallResponse,
7+
HistoryConversationText,
8+
HistoryFunctionCall,
9+
} from "../lib/types";
410
import { AbstractLiveClient } from "./AbstractLiveClient";
511

612
export class AgentLiveClient extends AbstractLiveClient {
@@ -167,4 +173,32 @@ export class AgentLiveClient extends AbstractLiveClient {
167173
public keepAlive(): void {
168174
this.send(JSON.stringify({ type: "KeepAlive" }));
169175
}
176+
177+
/**
178+
* Send conversation history text to provide context to the agent.
179+
* @param historyMessage - The history conversation text message.
180+
*/
181+
public sendHistoryConversationText(historyMessage: HistoryConversationText): void {
182+
this.send(JSON.stringify(historyMessage));
183+
}
184+
185+
/**
186+
* Send function call history to provide context to the agent.
187+
* @param historyMessage - The history function call message.
188+
*/
189+
public sendHistoryFunctionCall(historyMessage: HistoryFunctionCall): void {
190+
this.send(JSON.stringify(historyMessage));
191+
}
192+
193+
/**
194+
* Send multiple history messages at once to provide comprehensive context to the agent.
195+
* @param historyMessages - Array of history messages (conversation text and/or function calls).
196+
*/
197+
public sendHistoryMessages(
198+
historyMessages: (HistoryConversationText | HistoryFunctionCall)[]
199+
): void {
200+
historyMessages.forEach((message) => {
201+
this.send(JSON.stringify(message));
202+
});
203+
}
170204
}

0 commit comments

Comments
 (0)