@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Hone Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,316 @@
1
+ # Hone SDK (TypeScript)
2
+
3
+ The official TypeScript/JavaScript SDK for [Hone](https://honeagents.ai) - the AI Experience Engineering Platform for tracking and improving LLM applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @honeagents/hone
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { Hone, AIProvider } from "@honeagents/hone";
15
+
16
+ // Initialize the client
17
+ const hone = new Hone({
18
+ apiKey: process.env.HONE_API_KEY!,
19
+ });
20
+
21
+ // Fetch an agent configuration
22
+ const agent = await hone.agent("customer-support", {
23
+ model: "gpt-4o",
24
+ provider: AIProvider.OpenAI,
25
+ defaultPrompt: `You are a helpful customer support agent for {{companyName}}.
26
+
27
+ Be friendly, professional, and always try to resolve the customer's issue.`,
28
+ params: {
29
+ companyName: "Acme Corp",
30
+ },
31
+ });
32
+
33
+ // Use the result with your LLM provider
34
+ console.log(agent.systemPrompt);
35
+ // => "You are a helpful customer support agent for Acme Corp..."
36
+ console.log(agent.model);
37
+ // => "gpt-4o"
38
+ console.log(agent.temperature);
39
+ // => 0.7 (or whatever is configured in Hone dashboard)
40
+ ```
41
+
42
+ ## Features
43
+
44
+ - **Agent Management**: Define and fetch agent configurations with system prompts and hyperparameters
45
+ - **Tool Definitions**: Manage tool/function descriptions for function calling
46
+ - **Text Prompts**: Reusable text templates that can be nested in agents or tools
47
+ - **Parameter Substitution**: Dynamic prompt templates with `{{variable}}` syntax
48
+ - **Nested Entities**: Compose prompts by nesting tools and prompts within agents
49
+ - **Graceful Fallbacks**: Falls back to local defaults when API is unavailable
50
+ - **Type Safety**: Full TypeScript support with comprehensive type definitions
51
+
52
+ ## API Reference
53
+
54
+ ### Initialization
55
+
56
+ ```typescript
57
+ import { Hone } from "@honeagents/hone";
58
+
59
+ const hone = new Hone({
60
+ apiKey: "your-api-key", // Required
61
+ baseUrl: "https://custom-url.com/api", // Optional, defaults to Hone API
62
+ timeout: 5000, // Optional, defaults to 10000ms
63
+ });
64
+ ```
65
+
66
+ ### `hone.agent(id, options)`
67
+
68
+ Fetches an agent configuration by ID.
69
+
70
+ ```typescript
71
+ const agent = await hone.agent("my-agent", {
72
+ // Required
73
+ model: "gpt-4o",
74
+ provider: "openai", // or use AIProvider.OpenAI
75
+ defaultPrompt: "You are a helpful assistant.",
76
+
77
+ // Optional
78
+ params: { userName: "Alice" },
79
+ temperature: 0.7,
80
+ maxTokens: 1000,
81
+ topP: 1,
82
+ frequencyPenalty: 0,
83
+ presencePenalty: 0,
84
+ stopSequences: [],
85
+ tools: ["search", "calculator"],
86
+ majorVersion: 1,
87
+ name: "My Agent",
88
+ extra: { customField: "value" }, // Custom data stored with the agent
89
+ });
90
+
91
+ // Returns AgentResult
92
+ console.log(agent.systemPrompt); // Evaluated prompt with params substituted
93
+ console.log(agent.model); // "gpt-4o"
94
+ console.log(agent.provider); // "openai"
95
+ console.log(agent.temperature); // number | null
96
+ console.log(agent.maxTokens); // number | null
97
+ console.log(agent.tools); // string[]
98
+ ```
99
+
100
+ ### `hone.tool(id, options)`
101
+
102
+ Fetches a tool definition by ID.
103
+
104
+ ```typescript
105
+ const tool = await hone.tool("web-search", {
106
+ defaultPrompt: "Search the web for: {{query}}",
107
+ params: { query: "latest news" },
108
+ majorVersion: 1,
109
+ });
110
+
111
+ // Returns ToolResult
112
+ console.log(tool.prompt); // "Search the web for: latest news"
113
+ ```
114
+
115
+ ### `hone.prompt(id, options)`
116
+
117
+ Fetches a reusable text prompt by ID.
118
+
119
+ ```typescript
120
+ const prompt = await hone.prompt("tone-guidelines", {
121
+ defaultPrompt: "Always be friendly and professional.",
122
+ majorVersion: 1,
123
+ });
124
+
125
+ // Returns TextPromptResult
126
+ console.log(prompt.text); // "Always be friendly and professional."
127
+ ```
128
+
129
+ ### `hone.track(id, messages, options)`
130
+
131
+ Track a conversation for analysis.
132
+
133
+ ```typescript
134
+ await hone.track(
135
+ "conversation-123",
136
+ [
137
+ { role: "user", content: "Hello!" },
138
+ { role: "assistant", content: "Hi there! How can I help?" },
139
+ ],
140
+ { sessionId: "session-abc" }
141
+ );
142
+ ```
143
+
144
+ ## Nesting Entities
145
+
146
+ You can compose complex prompts by nesting tools and prompts within agents:
147
+
148
+ ```typescript
149
+ const agent = await hone.agent("complex-agent", {
150
+ model: "gpt-4o",
151
+ provider: "openai",
152
+ defaultPrompt: `You are an assistant with the following guidelines:
153
+
154
+ {{guidelines}}
155
+
156
+ You have access to these tools:
157
+ - Search: {{searchTool}}
158
+ - Calculator: {{calcTool}}`,
159
+ params: {
160
+ guidelines: {
161
+ defaultPrompt: "Be helpful, accurate, and concise.",
162
+ },
163
+ searchTool: {
164
+ defaultPrompt: "Search the web for information.",
165
+ },
166
+ calcTool: {
167
+ defaultPrompt: "Perform mathematical calculations.",
168
+ },
169
+ },
170
+ });
171
+ ```
172
+
173
+ ## Provider Constants
174
+
175
+ Use type-safe provider constants:
176
+
177
+ ```typescript
178
+ import { AIProvider, isValidProvider, getProviderDisplayName } from "@honeagents/hone";
179
+
180
+ // Use enum values
181
+ const config = {
182
+ provider: AIProvider.OpenAI, // "openai"
183
+ model: "gpt-4o",
184
+ };
185
+
186
+ // Validate provider strings
187
+ if (isValidProvider(userInput)) {
188
+ // userInput is typed as AIProviderValue
189
+ }
190
+
191
+ // Get display names
192
+ getProviderDisplayName("openai"); // "OpenAI"
193
+ getProviderDisplayName("amazon-bedrock"); // "Amazon Bedrock"
194
+ ```
195
+
196
+ ### Supported Providers
197
+
198
+ | Provider | Value | Display Name |
199
+ | ------------------ | ----------------- | ------------------- |
200
+ | OpenAI | `openai` | OpenAI |
201
+ | Anthropic | `anthropic` | Anthropic |
202
+ | Google AI | `google` | Google AI |
203
+ | Google Vertex AI | `google-vertex` | Google Vertex AI |
204
+ | Azure OpenAI | `azure` | Azure OpenAI |
205
+ | xAI | `xai` | xAI |
206
+ | Mistral AI | `mistral` | Mistral AI |
207
+ | Cohere | `cohere` | Cohere |
208
+ | Groq | `groq` | Groq |
209
+ | Together.ai | `togetherai` | Together.ai |
210
+ | Fireworks | `fireworks` | Fireworks |
211
+ | DeepInfra | `deepinfra` | DeepInfra |
212
+ | DeepSeek | `deepseek` | DeepSeek |
213
+ | Cerebras | `cerebras` | Cerebras |
214
+ | Perplexity | `perplexity` | Perplexity |
215
+ | Amazon Bedrock | `amazon-bedrock` | Amazon Bedrock |
216
+ | Baseten | `baseten` | Baseten |
217
+
218
+ ## Tool Tracking Helpers
219
+
220
+ Utilities for extracting messages from different LLM provider formats:
221
+
222
+ ```typescript
223
+ import {
224
+ extractOpenAIMessages,
225
+ extractAnthropicMessages,
226
+ extractGeminiMessages,
227
+ createToolResultMessage,
228
+ // Short aliases
229
+ fromOpenAI,
230
+ fromAnthropic,
231
+ fromGemini,
232
+ toolResult,
233
+ } from "@honeagents/hone";
234
+
235
+ // Extract messages from OpenAI response
236
+ const messages = extractOpenAIMessages(openaiResponse);
237
+
238
+ // Create a tool result message
239
+ const resultMessage = createToolResultMessage("tool-call-id", "result data");
240
+ ```
241
+
242
+ ## Environment Variables
243
+
244
+ | Variable | Description |
245
+ | --------------- | ------------------------------------------ |
246
+ | `HONE_API_KEY` | Your Hone API key |
247
+ | `HONE_API_URL` | Custom API URL (optional, for development) |
248
+
249
+ ## Error Handling
250
+
251
+ The SDK gracefully falls back to local defaults when the API is unavailable:
252
+
253
+ ```typescript
254
+ const agent = await hone.agent("my-agent", {
255
+ model: "gpt-4o",
256
+ provider: "openai",
257
+ defaultPrompt: "Fallback prompt if API fails",
258
+ });
259
+
260
+ // If API call fails, agent.systemPrompt will be "Fallback prompt if API fails"
261
+ // and hyperparameters will use the values from options
262
+ ```
263
+
264
+ ## TypeScript Support
265
+
266
+ The SDK is written in TypeScript and provides comprehensive type definitions:
267
+
268
+ ```typescript
269
+ import type {
270
+ HoneClient,
271
+ HoneConfig,
272
+ AgentResult,
273
+ ToolResult,
274
+ TextPromptResult,
275
+ GetAgentOptions,
276
+ GetToolOptions,
277
+ GetTextPromptOptions,
278
+ Message,
279
+ ToolCall,
280
+ AIProviderValue,
281
+ } from "@honeagents/hone";
282
+ ```
283
+
284
+ ### Generic Extra Data
285
+
286
+ You can type custom extra data stored with agents:
287
+
288
+ ```typescript
289
+ type MyExtra = {
290
+ customField: string;
291
+ anotherField: number;
292
+ };
293
+
294
+ const agent = await hone.agent<MyExtra>("my-agent", {
295
+ model: "gpt-4o",
296
+ provider: "openai",
297
+ defaultPrompt: "...",
298
+ extra: {
299
+ customField: "value",
300
+ anotherField: 42,
301
+ },
302
+ });
303
+
304
+ // agent.customField is typed as string
305
+ // agent.anotherField is typed as number
306
+ ```
307
+
308
+ ## License
309
+
310
+ MIT License - see [LICENSE](./LICENSE) for details.
311
+
312
+ ## Links
313
+
314
+ - [Hone Platform](https://honeagents.ai)
315
+ - [Documentation](https://docs.honeagents.ai)
316
+ - [GitHub Issues](https://github.com/honeagents/hone-node/issues)