Skip to content

Commit d604d5b

Browse files
committed
Generic type for tool calls
1 parent 93633f8 commit d604d5b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

packages/agent-sdk/src/autonomous.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const BITTE_API_URL =
22
"https://ai-runtime-446257178793.europe-west1.run.app/chat";
33

4-
export interface ToolResult {
4+
export interface ToolResult<T = Record<string, unknown>> {
55
toolCallId: string;
66
result: {
77
error?: string;
8-
data?: unknown;
8+
data?: T;
99
};
1010
}
1111

12-
export interface AgentResponse {
12+
export interface AgentResponse<T = Record<string, unknown>> {
1313
content: string;
14-
toolResults: ToolResult[];
14+
toolResults: ToolResult<T>[];
1515
messageId: string;
1616
finishReason: string;
1717
agentId: string;
@@ -38,14 +38,14 @@ export interface ChatPayload {
3838
config: ChatConfig;
3939
}
4040

41-
export async function callAgent(
41+
export async function callAgent<T = Record<string, unknown>>(
4242
accountId: string,
4343
message: string,
4444
agentId: string,
4545
evmAddress: string = "",
4646
suiAddress: string = "",
4747
solanaAddress: string = "",
48-
): Promise<AgentResponse> {
48+
): Promise<AgentResponse<T>> {
4949
const chatId = `chat_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
5050

5151
const payload: ChatPayload = {
@@ -84,10 +84,7 @@ export async function callAgent(
8484
let content = "";
8585
let finishReason = "";
8686
let resultAgentId = "";
87-
const toolResults: {
88-
toolCallId: string;
89-
result: { error?: string; data?: unknown };
90-
}[] = [];
87+
const toolResults: ToolResult<T>[] = [];
9188

9289
for (const line of lines) {
9390
const prefix = line.substring(0, 2);
@@ -129,10 +126,7 @@ export async function callAgent(
129126

130127
return {
131128
content: content.trim(),
132-
toolResults: toolResults.map((toolResult) => ({
133-
toolCallId: toolResult.toolCallId,
134-
result: toolResult.result,
135-
})),
129+
toolResults,
136130
messageId,
137131
finishReason,
138132
agentId: resultAgentId,

0 commit comments

Comments
 (0)