@honeagents/hone 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +316 -0
- package/dist/index.d.mts +674 -0
- package/dist/index.d.ts +674 -0
- package/dist/index.js +570 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +543 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Provider definitions compatible with Vercel AI SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides type-safe provider identifiers that align with
|
|
5
|
+
* the Vercel AI SDK's official provider packages (@ai-sdk/*).
|
|
6
|
+
*
|
|
7
|
+
* @see https://ai-sdk.dev/providers/ai-sdk-providers
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { AIProvider } from "@honeagents/hone";
|
|
12
|
+
*
|
|
13
|
+
* const agent = await hone.agent("my-agent", {
|
|
14
|
+
* provider: AIProvider.OpenAI,
|
|
15
|
+
* model: "gpt-4o",
|
|
16
|
+
* defaultPrompt: "You are a helpful assistant.",
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Supported AI providers from the Vercel AI SDK ecosystem.
|
|
22
|
+
*
|
|
23
|
+
* These correspond to the official @ai-sdk/* provider packages.
|
|
24
|
+
* Use these identifiers when specifying the `provider` field in agent options.
|
|
25
|
+
*/
|
|
26
|
+
declare enum AIProvider {
|
|
27
|
+
/** OpenAI - GPT models (gpt-4o, gpt-4, gpt-3.5-turbo, etc.) */
|
|
28
|
+
OpenAI = "openai",
|
|
29
|
+
/** Anthropic - Claude models (claude-3-opus, claude-3-sonnet, claude-3-haiku, etc.) */
|
|
30
|
+
Anthropic = "anthropic",
|
|
31
|
+
/** Google Generative AI - Gemini models (gemini-pro, gemini-1.5-pro, etc.) */
|
|
32
|
+
Google = "google",
|
|
33
|
+
/** Google Vertex AI - Enterprise Gemini models */
|
|
34
|
+
GoogleVertex = "google-vertex",
|
|
35
|
+
/** Azure OpenAI Service - Azure-hosted OpenAI models */
|
|
36
|
+
Azure = "azure",
|
|
37
|
+
/** xAI - Grok models */
|
|
38
|
+
XAI = "xai",
|
|
39
|
+
/** Mistral AI - Mistral models (mistral-large, mistral-medium, etc.) */
|
|
40
|
+
Mistral = "mistral",
|
|
41
|
+
/** Cohere - Command models */
|
|
42
|
+
Cohere = "cohere",
|
|
43
|
+
/** Groq - Fast inference for open models */
|
|
44
|
+
Groq = "groq",
|
|
45
|
+
/** Together.ai - Open model hosting */
|
|
46
|
+
TogetherAI = "togetherai",
|
|
47
|
+
/** Fireworks - Fast inference platform */
|
|
48
|
+
Fireworks = "fireworks",
|
|
49
|
+
/** DeepInfra - Model inference */
|
|
50
|
+
DeepInfra = "deepinfra",
|
|
51
|
+
/** DeepSeek - DeepSeek models */
|
|
52
|
+
DeepSeek = "deepseek",
|
|
53
|
+
/** Cerebras - Fast inference */
|
|
54
|
+
Cerebras = "cerebras",
|
|
55
|
+
/** Perplexity - Perplexity models with web search */
|
|
56
|
+
Perplexity = "perplexity",
|
|
57
|
+
/** Amazon Bedrock - AWS-hosted models */
|
|
58
|
+
AmazonBedrock = "amazon-bedrock",
|
|
59
|
+
/** Baseten - Model hosting platform */
|
|
60
|
+
Baseten = "baseten"
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Type representing all valid provider string values.
|
|
64
|
+
* Use this when you need a union type of provider strings.
|
|
65
|
+
*/
|
|
66
|
+
type AIProviderValue = `${AIProvider}`;
|
|
67
|
+
/**
|
|
68
|
+
* Array of all provider values for runtime validation.
|
|
69
|
+
*/
|
|
70
|
+
declare const AI_PROVIDER_VALUES: readonly AIProviderValue[];
|
|
71
|
+
/**
|
|
72
|
+
* Check if a string is a valid AI provider.
|
|
73
|
+
*
|
|
74
|
+
* @param value - The string to check
|
|
75
|
+
* @returns True if the value is a valid AIProvider
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* if (isValidProvider(userInput)) {
|
|
80
|
+
* // userInput is typed as AIProviderValue
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function isValidProvider(value: string): value is AIProviderValue;
|
|
85
|
+
/**
|
|
86
|
+
* Get the display name for a provider.
|
|
87
|
+
*
|
|
88
|
+
* @param provider - The provider identifier
|
|
89
|
+
* @returns Human-readable provider name
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* getProviderDisplayName("openai") // "OpenAI"
|
|
94
|
+
* getProviderDisplayName("amazon-bedrock") // "Amazon Bedrock"
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function getProviderDisplayName(provider: AIProviderValue | string): string;
|
|
98
|
+
|
|
99
|
+
type HoneConfig = {
|
|
100
|
+
apiKey: string;
|
|
101
|
+
baseUrl?: string;
|
|
102
|
+
timeout?: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Supported entity types in the Hone system.
|
|
106
|
+
*/
|
|
107
|
+
type EntityType = "agent" | "tool" | "prompt";
|
|
108
|
+
type ParamsValue = string | GetTextPromptOptions;
|
|
109
|
+
type Params = Record<string, ParamsValue>;
|
|
110
|
+
type SimpleParams = Record<string, string>;
|
|
111
|
+
/**
|
|
112
|
+
* Hyperparameters for LLM configuration.
|
|
113
|
+
* Used by agents to configure LLM behavior.
|
|
114
|
+
*/
|
|
115
|
+
type Hyperparameters = {
|
|
116
|
+
/** LLM model identifier (e.g., "gpt-4", "claude-3-opus") - REQUIRED for agents */
|
|
117
|
+
model?: string;
|
|
118
|
+
/**
|
|
119
|
+
* LLM provider identifier. Use AIProvider enum for type safety.
|
|
120
|
+
* @example AIProvider.OpenAI, AIProvider.Anthropic, "openai", "anthropic"
|
|
121
|
+
*/
|
|
122
|
+
provider?: AIProviderValue | (string & Record<string, never>);
|
|
123
|
+
/** Sampling temperature (0.00 to 2.00) */
|
|
124
|
+
temperature?: number;
|
|
125
|
+
/** Maximum output tokens */
|
|
126
|
+
maxTokens?: number;
|
|
127
|
+
/** Nucleus sampling parameter (0.00 to 1.00) */
|
|
128
|
+
topP?: number;
|
|
129
|
+
/** Repetition penalty (-2.00 to 2.00) */
|
|
130
|
+
frequencyPenalty?: number;
|
|
131
|
+
/** Topic diversity penalty (-2.00 to 2.00) */
|
|
132
|
+
presencePenalty?: number;
|
|
133
|
+
/** Array of stop tokens */
|
|
134
|
+
stopSequences?: string[];
|
|
135
|
+
/** Array of tool IDs this agent can use */
|
|
136
|
+
tools?: string[];
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Required hyperparameters for agents.
|
|
140
|
+
* Model and provider are mandatory.
|
|
141
|
+
*/
|
|
142
|
+
type RequiredAgentHyperparameters = Required<Pick<Hyperparameters, "model" | "provider">> & Omit<Hyperparameters, "model" | "provider">;
|
|
143
|
+
/**
|
|
144
|
+
* Options for fetching an agent.
|
|
145
|
+
* Model and provider are REQUIRED.
|
|
146
|
+
*
|
|
147
|
+
* @typeParam TExtra - Type for custom extra data that will be stored and returned
|
|
148
|
+
*/
|
|
149
|
+
type GetAgentOptions<TExtra extends Record<string, unknown> = Record<string, unknown>> = RequiredAgentHyperparameters & {
|
|
150
|
+
/**
|
|
151
|
+
* The major version of the agent. SDK controls this value.
|
|
152
|
+
* When majorVersion changes, minorVersion resets to 0.
|
|
153
|
+
* If not specified, defaults to 1.
|
|
154
|
+
*/
|
|
155
|
+
majorVersion?: number;
|
|
156
|
+
/**
|
|
157
|
+
* Optional name for the agent for easier identification.
|
|
158
|
+
* Will fallback to id if not provided.
|
|
159
|
+
*/
|
|
160
|
+
name?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Parameters to substitute into the prompt. You can also nest agent/tool calls here.
|
|
163
|
+
*/
|
|
164
|
+
params?: Params;
|
|
165
|
+
/**
|
|
166
|
+
* The default prompt to use if none is found in the database.
|
|
167
|
+
* The use of variables should be in the form `{{variableName}}`.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* agent("greeting", {
|
|
172
|
+
* model: "gpt-4",
|
|
173
|
+
* provider: "openai",
|
|
174
|
+
* params: { userName: "Alice" },
|
|
175
|
+
* defaultPrompt: "Hello, {{userName}}! Welcome to our service.",
|
|
176
|
+
* })
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
defaultPrompt: string;
|
|
180
|
+
/**
|
|
181
|
+
* Custom extra data to store with the agent.
|
|
182
|
+
* This data is stored in the database and returned in the AgentResult.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* agent<{ customField: string }>("my-agent", {
|
|
187
|
+
* model: "gpt-4",
|
|
188
|
+
* provider: "openai",
|
|
189
|
+
* defaultPrompt: "...",
|
|
190
|
+
* extra: { customField: "my-value" },
|
|
191
|
+
* })
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
extra?: TExtra;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Base result returned by hone.agent() without extra data.
|
|
198
|
+
* Contains both the evaluated system prompt and hyperparameters.
|
|
199
|
+
*/
|
|
200
|
+
type BaseAgentResult = {
|
|
201
|
+
/** The fully evaluated system prompt with all parameters substituted */
|
|
202
|
+
systemPrompt: string;
|
|
203
|
+
/** LLM model identifier (e.g., "gpt-4", "claude-3-opus") */
|
|
204
|
+
model: string;
|
|
205
|
+
/** LLM provider (e.g., "openai", "anthropic") */
|
|
206
|
+
provider: string;
|
|
207
|
+
/** Sampling temperature (0.00 to 2.00) */
|
|
208
|
+
temperature: number | null;
|
|
209
|
+
/** Maximum output tokens */
|
|
210
|
+
maxTokens: number | null;
|
|
211
|
+
/** Nucleus sampling parameter (0.00 to 1.00) */
|
|
212
|
+
topP: number | null;
|
|
213
|
+
/** Repetition penalty (-2.00 to 2.00) */
|
|
214
|
+
frequencyPenalty: number | null;
|
|
215
|
+
/** Topic diversity penalty (-2.00 to 2.00) */
|
|
216
|
+
presencePenalty: number | null;
|
|
217
|
+
/** Array of stop tokens */
|
|
218
|
+
stopSequences: string[];
|
|
219
|
+
/** Array of allowed tool IDs */
|
|
220
|
+
tools: string[];
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* The result returned by hone.agent()
|
|
224
|
+
* Contains the evaluated system prompt, hyperparameters, and any extra data.
|
|
225
|
+
*
|
|
226
|
+
* @typeParam TExtra - Type for custom extra data that was stored with the agent
|
|
227
|
+
*/
|
|
228
|
+
type AgentResult<TExtra extends Record<string, unknown> = Record<string, unknown>> = BaseAgentResult & TExtra;
|
|
229
|
+
type HoneAgent = <TExtra extends Record<string, unknown> = Record<string, unknown>>(id: string, options: GetAgentOptions<TExtra>) => Promise<AgentResult<TExtra>>;
|
|
230
|
+
/**
|
|
231
|
+
* Options for fetching a tool.
|
|
232
|
+
* Tools don't have hyperparameters - they're just versioned text templates.
|
|
233
|
+
*/
|
|
234
|
+
type GetToolOptions = {
|
|
235
|
+
/**
|
|
236
|
+
* The major version of the tool. SDK controls this value.
|
|
237
|
+
* When majorVersion changes, minorVersion resets to 0.
|
|
238
|
+
* If not specified, defaults to 1.
|
|
239
|
+
*/
|
|
240
|
+
majorVersion?: number;
|
|
241
|
+
/**
|
|
242
|
+
* Optional name for the tool for easier identification.
|
|
243
|
+
* Will fallback to id if not provided.
|
|
244
|
+
*/
|
|
245
|
+
name?: string;
|
|
246
|
+
/**
|
|
247
|
+
* Parameters to substitute into the prompt. You can also nest agent/tool calls here.
|
|
248
|
+
*/
|
|
249
|
+
params?: Params;
|
|
250
|
+
/**
|
|
251
|
+
* The default prompt/description to use if none is found in the database.
|
|
252
|
+
* The use of variables should be in the form `{{variableName}}`.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* tool("search", {
|
|
257
|
+
* params: { query: "weather" },
|
|
258
|
+
* defaultPrompt: "Search the web for: {{query}}",
|
|
259
|
+
* })
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
defaultPrompt: string;
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* The result returned by hone.tool()
|
|
266
|
+
* Contains the evaluated prompt with parameters substituted.
|
|
267
|
+
*/
|
|
268
|
+
type ToolResult = {
|
|
269
|
+
/** The fully evaluated prompt with all parameters substituted */
|
|
270
|
+
prompt: string;
|
|
271
|
+
};
|
|
272
|
+
type HoneTool = (id: string, options: GetToolOptions) => Promise<ToolResult>;
|
|
273
|
+
/**
|
|
274
|
+
* Options for fetching a text prompt.
|
|
275
|
+
* Text prompts are simple versioned text templates with no hyperparameters.
|
|
276
|
+
* They can be nested inside agents, tools, or other prompts.
|
|
277
|
+
*/
|
|
278
|
+
type GetTextPromptOptions = {
|
|
279
|
+
/**
|
|
280
|
+
* The major version of the prompt. SDK controls this value.
|
|
281
|
+
* When majorVersion changes, minorVersion resets to 0.
|
|
282
|
+
* If not specified, defaults to 1.
|
|
283
|
+
*/
|
|
284
|
+
majorVersion?: number;
|
|
285
|
+
/**
|
|
286
|
+
* Optional name for the prompt for easier identification.
|
|
287
|
+
* Will fallback to id if not provided.
|
|
288
|
+
*/
|
|
289
|
+
name?: string;
|
|
290
|
+
/**
|
|
291
|
+
* Parameters to substitute into the prompt. You can also nest other prompts here.
|
|
292
|
+
*/
|
|
293
|
+
params?: Params;
|
|
294
|
+
/**
|
|
295
|
+
* The default text to use if none is found in the database.
|
|
296
|
+
* The use of variables should be in the form `{{variableName}}`.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* prompt("tone-guidelines", {
|
|
301
|
+
* defaultPrompt: "Always be friendly and professional.",
|
|
302
|
+
* })
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
defaultPrompt: string;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* The result returned by hone.prompt()
|
|
309
|
+
* Contains the evaluated text with parameters substituted.
|
|
310
|
+
*/
|
|
311
|
+
type TextPromptResult = {
|
|
312
|
+
/** The fully evaluated text with all parameters substituted */
|
|
313
|
+
text: string;
|
|
314
|
+
};
|
|
315
|
+
type HoneTextPrompt = (id: string, options: GetTextPromptOptions) => Promise<TextPromptResult>;
|
|
316
|
+
/**
|
|
317
|
+
* Represents a tool call made by the assistant.
|
|
318
|
+
* Compatible with OpenAI's function calling format.
|
|
319
|
+
*/
|
|
320
|
+
type ToolCall = {
|
|
321
|
+
/** Unique identifier for this tool call */
|
|
322
|
+
id: string;
|
|
323
|
+
/** Name of the tool/function being called */
|
|
324
|
+
name: string;
|
|
325
|
+
/** JSON string of the arguments to pass to the tool */
|
|
326
|
+
arguments: string;
|
|
327
|
+
};
|
|
328
|
+
type Message = {
|
|
329
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
330
|
+
content: string;
|
|
331
|
+
/** Tool calls requested by the assistant (present when role is "assistant") */
|
|
332
|
+
tool_calls?: ToolCall[];
|
|
333
|
+
/** ID of the tool call this message is responding to (present when role is "tool") */
|
|
334
|
+
tool_call_id?: string;
|
|
335
|
+
};
|
|
336
|
+
type TrackConversationOptions = {
|
|
337
|
+
sessionId: string;
|
|
338
|
+
};
|
|
339
|
+
type HoneTrack = (id: string, messages: Message[], options: TrackConversationOptions) => Promise<void>;
|
|
340
|
+
type HoneClient = {
|
|
341
|
+
/**
|
|
342
|
+
* Fetches and evaluates an agent by its ID with the given options.
|
|
343
|
+
* @param id The unique identifier for the agent.
|
|
344
|
+
* @param options Options for fetching and evaluating the agent. Model and provider are required.
|
|
345
|
+
* @returns A Promise that resolves to an AgentResult containing systemPrompt and hyperparameters.
|
|
346
|
+
*/
|
|
347
|
+
agent: HoneAgent;
|
|
348
|
+
/**
|
|
349
|
+
* Fetches and evaluates a tool by its ID with the given options.
|
|
350
|
+
* @param id The unique identifier for the tool.
|
|
351
|
+
* @param options Options for fetching and evaluating the tool.
|
|
352
|
+
* @returns A Promise that resolves to a ToolResult containing the evaluated prompt.
|
|
353
|
+
*/
|
|
354
|
+
tool: HoneTool;
|
|
355
|
+
/**
|
|
356
|
+
* Fetches and evaluates a text prompt by its ID with the given options.
|
|
357
|
+
* @param id The unique identifier for the prompt.
|
|
358
|
+
* @param options Options for fetching and evaluating the prompt.
|
|
359
|
+
* @returns A Promise that resolves to a TextPromptResult containing the evaluated text.
|
|
360
|
+
*/
|
|
361
|
+
prompt: HoneTextPrompt;
|
|
362
|
+
/**
|
|
363
|
+
* Adds messages to track a conversation under the given ID.
|
|
364
|
+
* @param id The unique identifier for the conversation to track.
|
|
365
|
+
* @param messages An array of Message objects representing the conversation.
|
|
366
|
+
* @param options Optional TrackConversationOptions such as sessionId.
|
|
367
|
+
*/
|
|
368
|
+
track: HoneTrack;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Internal representation of an entity node in the tree.
|
|
372
|
+
*/
|
|
373
|
+
type EntityNode = Hyperparameters & {
|
|
374
|
+
id: string;
|
|
375
|
+
type: EntityType;
|
|
376
|
+
name?: string;
|
|
377
|
+
majorVersion?: number;
|
|
378
|
+
params: SimpleParams;
|
|
379
|
+
prompt: string;
|
|
380
|
+
children: EntityNode[];
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Agent node is an EntityNode with type="agent"
|
|
384
|
+
*/
|
|
385
|
+
type AgentNode = EntityNode & {
|
|
386
|
+
type: "agent";
|
|
387
|
+
};
|
|
388
|
+
type AgentRequestItem = Omit<AgentNode, "children" | "params"> & {
|
|
389
|
+
paramKeys: string[];
|
|
390
|
+
childrenIds: string[];
|
|
391
|
+
};
|
|
392
|
+
type AgentRequest = {
|
|
393
|
+
agents: {
|
|
394
|
+
rootId: string;
|
|
395
|
+
map: Record<string, AgentRequestItem>;
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
type AgentResponseItem = {
|
|
399
|
+
prompt: string;
|
|
400
|
+
model: string | null;
|
|
401
|
+
provider: string | null;
|
|
402
|
+
temperature: number | null;
|
|
403
|
+
maxTokens: number | null;
|
|
404
|
+
topP: number | null;
|
|
405
|
+
frequencyPenalty: number | null;
|
|
406
|
+
presencePenalty: number | null;
|
|
407
|
+
stopSequences: string[];
|
|
408
|
+
tools: string[];
|
|
409
|
+
};
|
|
410
|
+
type AgentResponse = Record<string, AgentResponseItem>;
|
|
411
|
+
/** @deprecated Use GetAgentOptions instead */
|
|
412
|
+
type GetPromptOptions = GetAgentOptions;
|
|
413
|
+
/** @deprecated Use AgentNode instead */
|
|
414
|
+
type PromptNode = AgentNode;
|
|
415
|
+
/** @deprecated Use AgentRequest instead */
|
|
416
|
+
type PromptRequest = AgentRequest;
|
|
417
|
+
/** @deprecated Use AgentResponse instead */
|
|
418
|
+
type PromptResponse = AgentResponse;
|
|
419
|
+
/** @deprecated Use HoneAgent instead */
|
|
420
|
+
type HonePrompt = HoneAgent;
|
|
421
|
+
|
|
422
|
+
declare class Hone implements HoneClient {
|
|
423
|
+
private apiKey;
|
|
424
|
+
private baseUrl;
|
|
425
|
+
private timeout;
|
|
426
|
+
constructor(config: HoneConfig);
|
|
427
|
+
private makeRequest;
|
|
428
|
+
agent<TExtra extends Record<string, unknown> = Record<string, unknown>>(id: string, options: GetAgentOptions<TExtra>): Promise<AgentResult<TExtra>>;
|
|
429
|
+
tool(id: string, options: GetToolOptions): Promise<ToolResult>;
|
|
430
|
+
prompt(id: string, options: GetTextPromptOptions): Promise<TextPromptResult>;
|
|
431
|
+
track(id: string, messages: Message[], options: TrackConversationOptions): Promise<void>;
|
|
432
|
+
}
|
|
433
|
+
declare function createHoneClient(config: HoneConfig): HoneClient;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Tool tracking helpers for the Hone SDK.
|
|
437
|
+
*
|
|
438
|
+
* These utilities help format tool calls and results for tracking conversations
|
|
439
|
+
* that include function calling / tool use.
|
|
440
|
+
*/
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Creates an assistant message containing tool calls.
|
|
444
|
+
*
|
|
445
|
+
* @param toolCalls - Array of tool calls the assistant is requesting
|
|
446
|
+
* @param content - Optional text content alongside tool calls (usually empty)
|
|
447
|
+
* @returns A Message object formatted for tool call requests
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* const message = createToolCallMessage([
|
|
452
|
+
* { id: "call_abc123", name: "get_weather", arguments: '{"location":"SF"}' }
|
|
453
|
+
* ]);
|
|
454
|
+
* // { role: "assistant", content: "", tool_calls: [...] }
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
declare function createToolCallMessage(toolCalls: ToolCall[], content?: string): Message;
|
|
458
|
+
/**
|
|
459
|
+
* Creates a tool result message responding to a specific tool call.
|
|
460
|
+
*
|
|
461
|
+
* @param toolCallId - The ID of the tool call this result responds to
|
|
462
|
+
* @param result - The result from executing the tool (will be stringified if not a string)
|
|
463
|
+
* @returns A Message object formatted as a tool response
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* const message = createToolResultMessage("call_abc123", { temp: 72, unit: "F" });
|
|
468
|
+
* // { role: "tool", content: '{"temp":72,"unit":"F"}', tool_call_id: "call_abc123" }
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
declare function createToolResultMessage(toolCallId: string, result: unknown): Message;
|
|
472
|
+
/**
|
|
473
|
+
* Extracts messages from an OpenAI chat completion response.
|
|
474
|
+
*
|
|
475
|
+
* Handles both regular assistant messages and messages with tool calls.
|
|
476
|
+
*
|
|
477
|
+
* @param response - The OpenAI chat completion response object
|
|
478
|
+
* @returns Array of Message objects ready to be tracked
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* import OpenAI from "openai";
|
|
483
|
+
*
|
|
484
|
+
* const openai = new OpenAI();
|
|
485
|
+
* const response = await openai.chat.completions.create({
|
|
486
|
+
* model: "gpt-4o",
|
|
487
|
+
* messages: [...],
|
|
488
|
+
* tools: [...]
|
|
489
|
+
* });
|
|
490
|
+
*
|
|
491
|
+
* const messages = extractOpenAIMessages(response);
|
|
492
|
+
* await hone.track("conversation", [...existingMessages, ...messages], { sessionId });
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
declare function extractOpenAIMessages(response: {
|
|
496
|
+
choices: Array<{
|
|
497
|
+
message: {
|
|
498
|
+
role: string;
|
|
499
|
+
content: string | null;
|
|
500
|
+
tool_calls?: Array<{
|
|
501
|
+
id: string;
|
|
502
|
+
function: {
|
|
503
|
+
name: string;
|
|
504
|
+
arguments: string;
|
|
505
|
+
};
|
|
506
|
+
}>;
|
|
507
|
+
};
|
|
508
|
+
}>;
|
|
509
|
+
}): Message[];
|
|
510
|
+
/**
|
|
511
|
+
* Extracts messages from an Anthropic Claude response.
|
|
512
|
+
*
|
|
513
|
+
* Handles both text responses and tool use blocks.
|
|
514
|
+
*
|
|
515
|
+
* @param response - The Anthropic message response object
|
|
516
|
+
* @returns Array of Message objects ready to be tracked
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```typescript
|
|
520
|
+
* import Anthropic from "@anthropic-ai/sdk";
|
|
521
|
+
*
|
|
522
|
+
* const anthropic = new Anthropic();
|
|
523
|
+
* const response = await anthropic.messages.create({
|
|
524
|
+
* model: "claude-sonnet-4-20250514",
|
|
525
|
+
* messages: [...],
|
|
526
|
+
* tools: [...]
|
|
527
|
+
* });
|
|
528
|
+
*
|
|
529
|
+
* const messages = extractAnthropicMessages(response);
|
|
530
|
+
* await hone.track("conversation", [...existingMessages, ...messages], { sessionId });
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
declare function extractAnthropicMessages(response: {
|
|
534
|
+
role: string;
|
|
535
|
+
content: Array<{
|
|
536
|
+
type: "text";
|
|
537
|
+
text: string;
|
|
538
|
+
} | {
|
|
539
|
+
type: "tool_use";
|
|
540
|
+
id: string;
|
|
541
|
+
name: string;
|
|
542
|
+
input: unknown;
|
|
543
|
+
}>;
|
|
544
|
+
}): Message[];
|
|
545
|
+
/**
|
|
546
|
+
* Extracts messages from a Google Gemini response.
|
|
547
|
+
*
|
|
548
|
+
* Handles both text responses and function call parts.
|
|
549
|
+
* Note: Gemini doesn't provide unique IDs for function calls, so we generate
|
|
550
|
+
* them using the format `gemini_{functionName}_{index}`.
|
|
551
|
+
*
|
|
552
|
+
* @param response - The Gemini GenerateContentResponse object
|
|
553
|
+
* @returns Array of Message objects ready to be tracked
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* ```typescript
|
|
557
|
+
* import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
558
|
+
*
|
|
559
|
+
* const genAI = new GoogleGenerativeAI(apiKey);
|
|
560
|
+
* const model = genAI.getGenerativeModel({ model: "gemini-pro" });
|
|
561
|
+
*
|
|
562
|
+
* const response = await model.generateContent({
|
|
563
|
+
* contents: [...],
|
|
564
|
+
* tools: [{ functionDeclarations: [...] }]
|
|
565
|
+
* });
|
|
566
|
+
*
|
|
567
|
+
* const messages = extractGeminiMessages(response);
|
|
568
|
+
* await hone.track("conversation", [...existingMessages, ...messages], { sessionId });
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
declare function extractGeminiMessages(response: {
|
|
572
|
+
candidates?: Array<{
|
|
573
|
+
content?: {
|
|
574
|
+
role?: string;
|
|
575
|
+
parts?: Array<{
|
|
576
|
+
text: string;
|
|
577
|
+
} | {
|
|
578
|
+
functionCall: {
|
|
579
|
+
name: string;
|
|
580
|
+
args: Record<string, unknown>;
|
|
581
|
+
};
|
|
582
|
+
}>;
|
|
583
|
+
};
|
|
584
|
+
}>;
|
|
585
|
+
}): Message[];
|
|
586
|
+
/**
|
|
587
|
+
* Short alias for createToolResultMessage.
|
|
588
|
+
* Creates a tool result message responding to a specific tool call.
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* messages.push(toolResult(toolCall.id, { temp: 72 }));
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
declare const toolResult: typeof createToolResultMessage;
|
|
596
|
+
/**
|
|
597
|
+
* Short alias for extractOpenAIMessages.
|
|
598
|
+
* Extracts messages from an OpenAI chat completion response.
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```typescript
|
|
602
|
+
* messages.push(...fromOpenAI(response));
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
605
|
+
declare const fromOpenAI: typeof extractOpenAIMessages;
|
|
606
|
+
/**
|
|
607
|
+
* Short alias for extractAnthropicMessages.
|
|
608
|
+
* Extracts messages from an Anthropic Claude response.
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* ```typescript
|
|
612
|
+
* messages.push(...fromAnthropic(response));
|
|
613
|
+
* ```
|
|
614
|
+
*/
|
|
615
|
+
declare const fromAnthropic: typeof extractAnthropicMessages;
|
|
616
|
+
/**
|
|
617
|
+
* Short alias for extractGeminiMessages.
|
|
618
|
+
* Extracts messages from a Google Gemini response.
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```typescript
|
|
622
|
+
* messages.push(...fromGemini(response));
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
declare const fromGemini: typeof extractGeminiMessages;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Constructs an AgentNode from the given id and GetAgentOptions.
|
|
629
|
+
* Traverses nested agents/tools recursively.
|
|
630
|
+
*
|
|
631
|
+
* @param id the unique identifier for the agent node
|
|
632
|
+
* @param options the GetAgentOptions containing agent details and parameters
|
|
633
|
+
* @param ancestorIds Set of ancestor IDs to detect circular references
|
|
634
|
+
* @returns AgentNode
|
|
635
|
+
* @throws Error if a self-reference or circular reference is detected
|
|
636
|
+
*/
|
|
637
|
+
declare function getAgentNode(id: string, options: GetAgentOptions, ancestorIds?: Set<string>): AgentNode;
|
|
638
|
+
/**
|
|
639
|
+
* Evaluates an AgentNode (alias for evaluateEntity for backwards compatibility)
|
|
640
|
+
*/
|
|
641
|
+
declare function evaluateAgent(node: AgentNode): string;
|
|
642
|
+
/**
|
|
643
|
+
* Inserts parameters into a prompt template.
|
|
644
|
+
*
|
|
645
|
+
* @param prompt The prompt template containing placeholders in the form `{{variableName}}`.
|
|
646
|
+
* @param params An object mapping variable names to their replacement values.
|
|
647
|
+
* @returns The prompt with all placeholders replaced by their corresponding values.
|
|
648
|
+
*/
|
|
649
|
+
declare function insertParamsIntoPrompt(prompt: string, params?: SimpleParams): string;
|
|
650
|
+
/**
|
|
651
|
+
* Traverses an AgentNode tree (alias for backwards compatibility)
|
|
652
|
+
*/
|
|
653
|
+
declare function traverseAgentNode(node: AgentNode, callback: (node: AgentNode, parentId: string | null) => void, parentId?: string | null): void;
|
|
654
|
+
/**
|
|
655
|
+
* Formats an AgentNode into an AgentRequest suitable for the /sync_agents API.
|
|
656
|
+
* (Backwards compatible format)
|
|
657
|
+
*/
|
|
658
|
+
declare function formatAgentRequest(node: AgentNode): AgentRequest;
|
|
659
|
+
/**
|
|
660
|
+
* Updates all nodes in an AgentNode tree (alias for backwards compatibility)
|
|
661
|
+
*/
|
|
662
|
+
declare function updateAgentNodes(root: AgentNode, callback: (agentNode: AgentNode) => AgentNode): AgentNode;
|
|
663
|
+
/** @deprecated Use getAgentNode instead */
|
|
664
|
+
declare const getPromptNode: typeof getAgentNode;
|
|
665
|
+
/** @deprecated Use evaluateAgent instead */
|
|
666
|
+
declare const evaluatePrompt: typeof evaluateAgent;
|
|
667
|
+
/** @deprecated Use traverseAgentNode instead */
|
|
668
|
+
declare const traversePromptNode: typeof traverseAgentNode;
|
|
669
|
+
/** @deprecated Use formatAgentRequest instead */
|
|
670
|
+
declare const formatPromptRequest: typeof formatAgentRequest;
|
|
671
|
+
/** @deprecated Use updateAgentNodes instead */
|
|
672
|
+
declare const updatePromptNodes: typeof updateAgentNodes;
|
|
673
|
+
|
|
674
|
+
export { AIProvider, type AIProviderValue, AI_PROVIDER_VALUES, type AgentNode, type AgentRequest, type AgentResponse, type AgentResponseItem, type AgentResult, type GetAgentOptions, type GetPromptOptions, Hone, type HoneAgent, type HoneClient, type HonePrompt, type HoneTrack, type Hyperparameters, type Message, type PromptNode, type PromptRequest, type PromptResponse, type ToolCall, createHoneClient, createToolCallMessage, createToolResultMessage, evaluateAgent, evaluatePrompt, extractAnthropicMessages, extractGeminiMessages, extractOpenAIMessages, formatAgentRequest, formatPromptRequest, fromAnthropic, fromGemini, fromOpenAI, getAgentNode, getPromptNode, getProviderDisplayName, insertParamsIntoPrompt, isValidProvider, toolResult, traverseAgentNode, traversePromptNode, updateAgentNodes, updatePromptNodes };
|