@iqai/adk 0.6.0 → 0.6.2
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/CHANGELOG.md +36 -32
- package/LICENSE.md +1 -1
- package/README.md +57 -52
- package/dist/index.d.mts +2210 -1832
- package/dist/index.d.ts +2210 -1832
- package/dist/index.js +6039 -3860
- package/dist/index.mjs +5816 -3637
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.6.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8f2167a: Adds a new suite of default ADK tools and refactors common tooling, including a major upgrade to the Google Search tool.
|
|
8
|
+
- Introduces a comprehensive set of **default tools** for the ADK (file system, shell, and web utilities) to provide a strong out-of-the-box agent experience.
|
|
9
|
+
- Adds a new **Tavily-powered web search tool** as part of the default toolset.
|
|
10
|
+
- Refactors the **Google Search tool** to use the real Google Custom Search API with Axios and Zod-based argument validation.
|
|
11
|
+
- Improves **type safety** across several common tools by replacing `any` return types with explicit interfaces.
|
|
12
|
+
- Updates the memory loading tool to return a structured result object.
|
|
13
|
+
|
|
14
|
+
This is a **non-breaking feature and refactor** that expands functionality, improves reliability, and strengthens type safety without changing existing APIs.
|
|
15
|
+
|
|
16
|
+
- f2dfa13: fix: remove unnecessary any type
|
|
17
|
+
- 96e9661: Add Context Caching support for ADK Apps using Gemini 2.0+ models.
|
|
18
|
+
|
|
19
|
+
This feature allows agents to reuse extended instructions or large contextual data across requests, reducing token usage and improving performance. Caching behavior is configurable at the App or Agent level via `contextCacheConfig`, with controls for minimum token threshold, cache TTL, and maximum usage intervals.
|
|
20
|
+
|
|
21
|
+
All agents within an App can benefit from shared cached context, minimizing redundant data sent to the model while preserving correctness.
|
|
22
|
+
|
|
23
|
+
## 0.6.1
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 3f78ed9: Fix: Wire up all missing plugin lifecycle callbacks
|
|
28
|
+
|
|
29
|
+
The PluginManager had several callback methods defined but never invoked, causing plugins implementing guardrails, logging, or error recovery to be silently ignored.
|
|
30
|
+
|
|
31
|
+
This fix adds the missing calls for:
|
|
32
|
+
- `beforeModelCallback` / `afterModelCallback` - intercept LLM requests/responses
|
|
33
|
+
- `onModelErrorCallback` - handle/recover from LLM errors
|
|
34
|
+
- `beforeToolCallback` / `afterToolCallback` - intercept tool execution
|
|
35
|
+
- `onToolErrorCallback` - handle/recover from tool errors
|
|
36
|
+
|
|
37
|
+
All 12 plugin callbacks are now properly wired up and invoked at the appropriate lifecycle points.
|
|
38
|
+
|
|
3
39
|
## 0.6.0
|
|
4
40
|
|
|
5
41
|
### Minor Changes
|
|
@@ -11,52 +47,44 @@
|
|
|
11
47
|
### ✨ New Features
|
|
12
48
|
|
|
13
49
|
**Modular Architecture**
|
|
14
|
-
|
|
15
50
|
- Refactored from monolithic to service-based design
|
|
16
51
|
- Separate modules for tracing, metrics, setup, and utilities
|
|
17
52
|
- Clean `telemetryService` API replacing low-level functions
|
|
18
53
|
|
|
19
54
|
**Metrics Support**
|
|
20
|
-
|
|
21
55
|
- Full metrics collection with OpenTelemetry SDK
|
|
22
56
|
- Counters: agent invocations, tool executions, LLM calls
|
|
23
57
|
- Histograms: duration tracking, token usage (input/output/total)
|
|
24
58
|
- OTLP HTTP exporter for metrics
|
|
25
59
|
|
|
26
60
|
**Privacy Controls**
|
|
27
|
-
|
|
28
61
|
- `ADK_CAPTURE_MESSAGE_CONTENT` environment variable
|
|
29
62
|
- Fine-grained control over sensitive data capture
|
|
30
63
|
- Disable prompt/completion logging for production
|
|
31
64
|
|
|
32
65
|
**Semantic Conventions**
|
|
33
|
-
|
|
34
66
|
- OpenTelemetry GenAI conventions (v1.37+)
|
|
35
67
|
- ADK-specific namespace (`adk.*`) for custom attributes
|
|
36
68
|
- Standardized attribute names across all spans
|
|
37
69
|
|
|
38
70
|
**Enhanced Tracing**
|
|
39
|
-
|
|
40
71
|
- Automatic agent invocation tracing with status tracking
|
|
41
72
|
- Tool execution spans with arguments and results
|
|
42
73
|
- LLM call tracing with token usage metrics
|
|
43
74
|
- Async generator support for streaming responses
|
|
44
75
|
|
|
45
76
|
**Resource Auto-Detection**
|
|
46
|
-
|
|
47
77
|
- Automatic detection of host, OS, and process information
|
|
48
78
|
- Custom resource attributes support
|
|
49
79
|
- Service instance identification
|
|
50
80
|
|
|
51
81
|
**Configuration**
|
|
52
|
-
|
|
53
82
|
- Comprehensive initialization options
|
|
54
83
|
- Sampling ratio control for production
|
|
55
84
|
- Configurable metric export intervals
|
|
56
85
|
- Custom OTLP headers for authentication
|
|
57
86
|
|
|
58
87
|
### 🔧 Breaking Changes
|
|
59
|
-
|
|
60
88
|
- `initializeTelemetry()` → `telemetryService.initialize()`
|
|
61
89
|
- `shutdownTelemetry()` → `telemetryService.shutdown()`
|
|
62
90
|
- Legacy `telemetry.ts` now wraps new service for backward compatibility
|
|
@@ -64,13 +92,11 @@
|
|
|
64
92
|
### 📊 Integration
|
|
65
93
|
|
|
66
94
|
All core components now automatically report metrics:
|
|
67
|
-
|
|
68
95
|
- `BaseAgent.runAsyncInternal()`: Agent metrics
|
|
69
96
|
- `functions.ts`: Tool execution metrics
|
|
70
97
|
- `base-llm-flow.ts`: LLM token and duration metrics
|
|
71
98
|
|
|
72
99
|
### 📚 Documentation
|
|
73
|
-
|
|
74
100
|
- Comprehensive README in `src/telemetry/`
|
|
75
101
|
- Updated observability example with Jaeger + Langfuse
|
|
76
102
|
- Practical examples demonstrating all features
|
|
@@ -78,12 +104,10 @@
|
|
|
78
104
|
### 🛠️ Technical Details
|
|
79
105
|
|
|
80
106
|
**Dependencies Added**:
|
|
81
|
-
|
|
82
107
|
- `@opentelemetry/sdk-metrics@^2.1.0`
|
|
83
108
|
- `@opentelemetry/exporter-metrics-otlp-http@^0.205.0`
|
|
84
109
|
|
|
85
110
|
**Supported Backends**:
|
|
86
|
-
|
|
87
111
|
- Jaeger (local development)
|
|
88
112
|
- Langfuse
|
|
89
113
|
- Datadog
|
|
@@ -106,14 +130,12 @@
|
|
|
106
130
|
The ADK telemetry system has been updated to fully comply with the latest OpenTelemetry GenAI semantic conventions. This ensures better interoperability with industry-standard observability platforms and provides richer, more standardized telemetry data.
|
|
107
131
|
|
|
108
132
|
**Breaking Changes:**
|
|
109
|
-
|
|
110
133
|
- `gen_ai.system` → `gen_ai.provider.name` (automatic provider detection from model names)
|
|
111
134
|
- `gen_ai.usage.total_tokens` removed (compute client-side: input + output)
|
|
112
135
|
- `call_llm` operation deprecated in favor of standard `chat`, `text_completion`, `generate_content`
|
|
113
136
|
- `traceCallback` signature changed: removed unused `targetName` parameter
|
|
114
137
|
|
|
115
138
|
**New Features:**
|
|
116
|
-
|
|
117
139
|
- Automatic provider detection (OpenAI, Anthropic, Google, AWS Bedrock, Mistral, Groq, Cohere, etc.)
|
|
118
140
|
- Enhanced LLM attributes: `response.id`, `response.model`, `output.type`, `top_k`, `frequency_penalty`, `presence_penalty`, `stop_sequences`, `seed`
|
|
119
141
|
- Structured content capture: `system_instructions`, `input.messages`, `output.messages`, `tool.definitions`
|
|
@@ -123,7 +145,6 @@
|
|
|
123
145
|
- Error type tracking: `error.type` attribute for low-cardinality error identification
|
|
124
146
|
|
|
125
147
|
**Backward Compatibility:**
|
|
126
|
-
|
|
127
148
|
- Deprecated constants are still available but will be removed in v1.0.0
|
|
128
149
|
- All `adk.*` namespace attributes remain unchanged
|
|
129
150
|
- Legacy content events preserved for one release cycle
|
|
@@ -135,7 +156,6 @@
|
|
|
135
156
|
### Patch Changes
|
|
136
157
|
|
|
137
158
|
- 27d6bd9: Refactored MCP sampling parameters to align with the official protocol specification by moving from direct model assertions to the `modelPreferences` hint system.
|
|
138
|
-
|
|
139
159
|
- **Protocol Alignment**
|
|
140
160
|
Removed the invalid `mcpParams.model` type assertion, as the MCP spec does not define a top-level string for the model in sampling requests.
|
|
141
161
|
|
|
@@ -160,7 +180,6 @@
|
|
|
160
180
|
- Improved event naming with descriptive suffixes (`.function_call`, `.final_response`, `.event`).
|
|
161
181
|
- Included `finishReason` in event metadata for enhanced execution context and observability.
|
|
162
182
|
- 0ada268: Added full plugin support across the agent lifecycle, enabling interception and extension of agent behavior during execution, model calls, and tool invocations.
|
|
163
|
-
|
|
164
183
|
- Integrated plugin manager into `BaseAgent`, giving plugins priority over canonical callbacks.
|
|
165
184
|
- Added `plugins` configuration to `AgentBuilder` and introduced `withPlugins()` API.
|
|
166
185
|
- Updated `LlmAgent` and `BaseAgent` flows to run plugin lifecycle hooks (`before/after agent`, `before/after model`, `before/after tool`, error hooks, etc.).
|
|
@@ -219,7 +238,6 @@
|
|
|
219
238
|
### Minor Changes
|
|
220
239
|
|
|
221
240
|
- 9c8441c: Enhanced CoinGecko MCP server support with remote endpoints
|
|
222
|
-
|
|
223
241
|
- **Enhanced createMcpConfig function**: Now automatically detects URLs and uses `mcp-remote` for remote MCP endpoints while maintaining backward compatibility with npm packages
|
|
224
242
|
- **Updated McpCoinGecko**: Now uses the remote CoinGecko MCP API endpoint (`https://mcp.api.coingecko.com/mcp`) instead of the npm package
|
|
225
243
|
- **Added McpCoinGeckoPro**: New function for accessing the professional CoinGecko MCP API endpoint (`https://mcp.pro-api.coingecko.com/mcp`) with enhanced features and higher rate limits
|
|
@@ -239,7 +257,6 @@
|
|
|
239
257
|
### Minor Changes
|
|
240
258
|
|
|
241
259
|
- c538a1a: feat(adk): align before/after model callback signatures with runtime (single object arg) and wire before/after tool callbacks into tool execution.
|
|
242
|
-
|
|
243
260
|
- beforeModelCallback/afterModelCallback now receive `{ callbackContext, llmRequest|llmResponse }` to match runtime invocation; removes need for casts in examples.
|
|
244
261
|
- beforeToolCallback/afterToolCallback are now invoked around tool execution; allow argument mutation and result override.
|
|
245
262
|
- tracing updated to include final args and the produced event.
|
|
@@ -280,21 +297,17 @@
|
|
|
280
297
|
### Patch Changes
|
|
281
298
|
|
|
282
299
|
- 2da690a: - **Dependency Updates:**
|
|
283
|
-
|
|
284
300
|
- Upgraded dependencies and devDependencies across multiple packages ensuring compatibility with the latest library versions.
|
|
285
301
|
|
|
286
302
|
- **Schema Handling:**
|
|
287
|
-
|
|
288
303
|
- Transitioned schema conversion to use `z.toJSONSchema`, reducing dependencies.
|
|
289
304
|
- Enhanced type safety in the workflow tool's schema handling.
|
|
290
305
|
|
|
291
306
|
- **Error Reporting and Validation:**
|
|
292
|
-
|
|
293
307
|
- Improved error messages in `AgentBuilder` for better debugging.
|
|
294
308
|
- Enhanced output validation for LLM.
|
|
295
309
|
|
|
296
310
|
- **AI SDK and Model Integration:**
|
|
297
|
-
|
|
298
311
|
- Refined model ID handling in `AiSdkLlm`.
|
|
299
312
|
- Updated field references to align with AI SDK changes.
|
|
300
313
|
|
|
@@ -314,17 +327,14 @@
|
|
|
314
327
|
### Minor Changes
|
|
315
328
|
|
|
316
329
|
- 3561208: ## Features
|
|
317
|
-
|
|
318
330
|
- Introduced conditional typing for multi-agent responses in `EnhancedRunner`, `BuiltAgent`, and `AgentBuilderWithSchema`. The ask() method now returns appropriate response type based on agent configuration.
|
|
319
331
|
- Improved `AgentBuilder` methods (asSequential, asParallel, and related build methods) for better type propagation and correct return types for multi-agent aggregators.
|
|
320
332
|
- Output schemas can no longer be set directly on multi-agent aggregators. Schemas must now be defined on individual sub-agents.
|
|
321
333
|
|
|
322
334
|
## Fixes
|
|
323
|
-
|
|
324
335
|
- Bugfix in mergeAgentRun that caused incorrect removal of resolved promises.
|
|
325
336
|
|
|
326
337
|
## Changes
|
|
327
|
-
|
|
328
338
|
- `ask()` implementation tailored to aggregate and return per-agent responses for multi-agent setups while maintaining schema validation for single-agent cases.
|
|
329
339
|
- Now, `AgentBuilder` and `BuiltAgent` are being re-exported explicitly from the ADK entrypoint for type preservation in bundled declarations.
|
|
330
340
|
|
|
@@ -375,7 +385,6 @@
|
|
|
375
385
|
This major enhancement improves the ADK CLI server's agent loading capabilities and adds new features to the core framework:
|
|
376
386
|
|
|
377
387
|
**CLI Server Improvements:**
|
|
378
|
-
|
|
379
388
|
- **Modular Architecture**: Refactored monolithic server file into organized modules (`server/index.ts`, `server/routes.ts`, `server/services.ts`, `server/types.ts`)
|
|
380
389
|
- **Enhanced Agent Resolution**: New `resolveAgentExport` method supports multiple export patterns:
|
|
381
390
|
- Direct agent exports: `export const agent = new LlmAgent(...)`
|
|
@@ -386,13 +395,11 @@
|
|
|
386
395
|
- **Improved TypeScript Import Handling**: Better project root detection and module resolution for TypeScript files
|
|
387
396
|
|
|
388
397
|
**Core Framework Enhancements:**
|
|
389
|
-
|
|
390
398
|
- **New AgentBuilder Method**: Added `withAgent()` method to directly provide existing agent instances with definition locking to prevent accidental configuration overwrites
|
|
391
399
|
- **Two-Tier Tool Deduplication**: Implemented robust deduplication logic to prevent duplicate function declarations that cause errors with LLM providers (especially Google)
|
|
392
400
|
- **Better Type Safety**: Improved type definitions and replaced `any[]` usage with proper typed interfaces
|
|
393
401
|
|
|
394
402
|
**Testing & Reliability:**
|
|
395
|
-
|
|
396
403
|
- **Comprehensive Test Coverage**: New `agent-resolution.test.ts` with extensive fixtures testing various agent export patterns
|
|
397
404
|
- **Multiple Test Fixtures**: Added 6 different agent export pattern examples for validation
|
|
398
405
|
- **Edge Case Handling**: Improved error handling and logging throughout the agent loading pipeline
|
|
@@ -402,7 +409,6 @@
|
|
|
402
409
|
- 1564b7b: Port Python evaluation framework to TypeScript
|
|
403
410
|
|
|
404
411
|
This change introduces a comprehensive evaluation framework for testing AI agent performance. Key features include:
|
|
405
|
-
|
|
406
412
|
- **Core evaluation engine** with agent-evaluator and local evaluation service
|
|
407
413
|
- **Built-in evaluators** for response matching, trajectory analysis, LLM-as-judge, and safety checks
|
|
408
414
|
- **Metrics system** with ROUGE scoring and tool trajectory analysis
|
|
@@ -535,14 +541,12 @@
|
|
|
535
541
|
This release introduces integration with Vercel's AI SDK, expanding the platform's capabilities to support a wider range of large language models without requiring manual maintenance of model synchronization.
|
|
536
542
|
|
|
537
543
|
## Key Features
|
|
538
|
-
|
|
539
544
|
- **AI-SDK Integration**: New `AiSdkLlm` class that integrates with Vercel AI SDK, supporting multiple providers (Google, OpenAI, Anthropic)
|
|
540
545
|
- **Tool Calling Support**: Robust tool calling capabilities with automatic transformation of ADK function declarations to AI SDK tool definitions using Zod schemas
|
|
541
546
|
- **Agent Builder Support**: Enhanced agent builder with AI-SDK model support
|
|
542
547
|
- **Example Implementation**: Complete weather agent example demonstrating AI-SDK usage with tool calling
|
|
543
548
|
|
|
544
549
|
## Technical Details
|
|
545
|
-
|
|
546
550
|
- Adds `ai-sdk.ts` model implementation with streaming support
|
|
547
551
|
- Implements message format conversion between ADK and AI SDK formats
|
|
548
552
|
- Supports both streaming and non-streaming model interactions
|
package/LICENSE.md
CHANGED
|
@@ -6,4 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
6
6
|
|
|
7
7
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
8
|
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -50,11 +50,11 @@ npm install @iqai/adk
|
|
|
50
50
|
### Simple Example
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
|
-
import { AgentBuilder } from
|
|
53
|
+
import { AgentBuilder } from "@iqai/adk";
|
|
54
54
|
|
|
55
|
-
const response = await AgentBuilder
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const response = await AgentBuilder.withModel("gpt-4.1").ask(
|
|
56
|
+
"What is the primary function of an AI agent?",
|
|
57
|
+
);
|
|
58
58
|
|
|
59
59
|
console.log(response);
|
|
60
60
|
```
|
|
@@ -76,8 +76,8 @@ The library uses `dotenv` to load these variables automatically if `dotenv.confi
|
|
|
76
76
|
Here's a fundamental example of creating and running an agent:
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
|
-
import { Agent } from
|
|
80
|
-
import dotenv from
|
|
79
|
+
import { Agent } from "@iqai/adk";
|
|
80
|
+
import dotenv from "dotenv";
|
|
81
81
|
|
|
82
82
|
// Load environment variables
|
|
83
83
|
dotenv.config();
|
|
@@ -87,7 +87,7 @@ const myAgent = new LlmAgent({
|
|
|
87
87
|
name: "simple_query_assistant",
|
|
88
88
|
model: "gemini-2.5-flash", // Or "gpt-4-turbo", "claude-3-opus"
|
|
89
89
|
description: "A basic assistant to answer questions.",
|
|
90
|
-
instructions: "You are a helpful AI. Respond clearly and concisely."
|
|
90
|
+
instructions: "You are a helpful AI. Respond clearly and concisely.",
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
// Asynchronously run the agent
|
|
@@ -97,7 +97,7 @@ async function runQuery() {
|
|
|
97
97
|
console.log(`User: ${query}`);
|
|
98
98
|
|
|
99
99
|
const response = await myAgent.run({
|
|
100
|
-
messages: [{ role:
|
|
100
|
+
messages: [{ role: "user", content: query }],
|
|
101
101
|
});
|
|
102
102
|
|
|
103
103
|
console.log(`Agent: ${response.content}`);
|
|
@@ -114,15 +114,14 @@ runQuery();
|
|
|
114
114
|
The `AgentBuilder` provides a fluent interface for creating agents with minimal boilerplate. It's perfect for rapid prototyping and reduces the complexity of agent setup.
|
|
115
115
|
|
|
116
116
|
```typescript
|
|
117
|
-
import { AgentBuilder } from
|
|
118
|
-
import dotenv from
|
|
117
|
+
import { AgentBuilder } from "@iqai/adk";
|
|
118
|
+
import dotenv from "dotenv";
|
|
119
119
|
|
|
120
120
|
dotenv.config();
|
|
121
121
|
|
|
122
122
|
// Simple agent creation and execution in one fluent chain
|
|
123
123
|
async function quickQuery() {
|
|
124
|
-
const response = await AgentBuilder
|
|
125
|
-
.create("query_assistant")
|
|
124
|
+
const response = await AgentBuilder.create("query_assistant")
|
|
126
125
|
.withModel("gemini-2.5-flash")
|
|
127
126
|
.withInstruction("You are a helpful AI. Respond clearly and concisely.")
|
|
128
127
|
.ask("What is the capital of France?");
|
|
@@ -132,11 +131,14 @@ async function quickQuery() {
|
|
|
132
131
|
|
|
133
132
|
// For more complex scenarios, build the agent and get full control
|
|
134
133
|
async function advancedSetup() {
|
|
135
|
-
const { agent, runner, session } = await AgentBuilder
|
|
136
|
-
|
|
134
|
+
const { agent, runner, session } = await AgentBuilder.create(
|
|
135
|
+
"research_assistant",
|
|
136
|
+
)
|
|
137
137
|
.withModel("gpt-4-turbo")
|
|
138
138
|
.withDescription("An advanced research assistant")
|
|
139
|
-
.withInstruction(
|
|
139
|
+
.withInstruction(
|
|
140
|
+
"You are a research assistant with access to various tools",
|
|
141
|
+
)
|
|
140
142
|
.withTools(new GoogleSearchTool(), new FileOperationsTool())
|
|
141
143
|
.withQuickSession("research-app", "researcher-456")
|
|
142
144
|
.build();
|
|
@@ -148,15 +150,13 @@ async function advancedSetup() {
|
|
|
148
150
|
// Specialized agent types for orchestration
|
|
149
151
|
async function createWorkflowAgent() {
|
|
150
152
|
// Sequential execution of multiple agents
|
|
151
|
-
const workflow = await AgentBuilder
|
|
152
|
-
.create("data_pipeline")
|
|
153
|
+
const workflow = await AgentBuilder.create("data_pipeline")
|
|
153
154
|
.asSequential([dataCollector, dataProcessor, dataAnalyzer])
|
|
154
155
|
.withQuickSession("pipeline-app", "admin")
|
|
155
156
|
.build();
|
|
156
157
|
|
|
157
158
|
// Parallel execution for concurrent tasks
|
|
158
|
-
const parallelAnalysis = await AgentBuilder
|
|
159
|
-
.create("multi_analysis")
|
|
159
|
+
const parallelAnalysis = await AgentBuilder.create("multi_analysis")
|
|
160
160
|
.asParallel([sentimentAnalyzer, topicExtractor, summaryGenerator])
|
|
161
161
|
.build();
|
|
162
162
|
}
|
|
@@ -176,8 +176,8 @@ async function createWorkflowAgent() {
|
|
|
176
176
|
Extend your agent's capabilities by defining and integrating custom tools.
|
|
177
177
|
|
|
178
178
|
```typescript
|
|
179
|
-
import { Agent, BaseTool } from
|
|
180
|
-
import dotenv from
|
|
179
|
+
import { Agent, BaseTool } from "@iqai/adk";
|
|
180
|
+
import dotenv from "dotenv";
|
|
181
181
|
|
|
182
182
|
dotenv.config();
|
|
183
183
|
|
|
@@ -185,8 +185,9 @@ dotenv.config();
|
|
|
185
185
|
class CalculatorTool extends BaseTool {
|
|
186
186
|
constructor() {
|
|
187
187
|
super({
|
|
188
|
-
name:
|
|
189
|
-
description:
|
|
188
|
+
name: "calculator",
|
|
189
|
+
description:
|
|
190
|
+
"Performs basic arithmetic operations: add, subtract, multiply, divide.",
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
193
|
|
|
@@ -195,30 +196,38 @@ class CalculatorTool extends BaseTool {
|
|
|
195
196
|
name: this.name,
|
|
196
197
|
description: this.description,
|
|
197
198
|
parameters: {
|
|
198
|
-
type:
|
|
199
|
+
type: "object",
|
|
199
200
|
properties: {
|
|
200
201
|
operation: {
|
|
201
|
-
type:
|
|
202
|
-
enum: [
|
|
202
|
+
type: "string",
|
|
203
|
+
enum: ["add", "subtract", "multiply", "divide"],
|
|
203
204
|
},
|
|
204
|
-
operand1: { type:
|
|
205
|
-
operand2: { type:
|
|
205
|
+
operand1: { type: "number" },
|
|
206
|
+
operand2: { type: "number" },
|
|
206
207
|
},
|
|
207
|
-
required: [
|
|
208
|
-
}
|
|
208
|
+
required: ["operation", "operand1", "operand2"],
|
|
209
|
+
},
|
|
209
210
|
};
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
async runAsync(args: {
|
|
213
|
+
async runAsync(args: {
|
|
214
|
+
operation: string;
|
|
215
|
+
operand1: number;
|
|
216
|
+
operand2: number;
|
|
217
|
+
}) {
|
|
213
218
|
const { operation, operand1, operand2 } = args;
|
|
214
219
|
switch (operation) {
|
|
215
|
-
case
|
|
216
|
-
|
|
217
|
-
case
|
|
218
|
-
|
|
219
|
-
|
|
220
|
+
case "add":
|
|
221
|
+
return { result: operand1 + operand2 };
|
|
222
|
+
case "subtract":
|
|
223
|
+
return { result: operand1 - operand2 };
|
|
224
|
+
case "multiply":
|
|
225
|
+
return { result: operand1 * operand2 };
|
|
226
|
+
case "divide":
|
|
227
|
+
if (operand2 === 0) return { error: "Cannot divide by zero." };
|
|
220
228
|
return { result: operand1 / operand2 };
|
|
221
|
-
default:
|
|
229
|
+
default:
|
|
230
|
+
return { error: `Unknown operation: ${operation}` };
|
|
222
231
|
}
|
|
223
232
|
}
|
|
224
233
|
}
|
|
@@ -229,14 +238,12 @@ const mathAgent = new LlmAgent({
|
|
|
229
238
|
model: "gpt-4-turbo", // Choose a model proficient with tool usage
|
|
230
239
|
instructions:
|
|
231
240
|
"You are a helpful assistant. Use the calculator tool for any mathematical calculations requested.",
|
|
232
|
-
tools: [new CalculatorTool()]
|
|
241
|
+
tools: [new CalculatorTool()],
|
|
233
242
|
});
|
|
234
243
|
|
|
235
244
|
async function performCalculation() {
|
|
236
245
|
const response = await mathAgent.run({
|
|
237
|
-
messages: [
|
|
238
|
-
{ role: 'user', content: 'What is 15 multiplied by 4?' }
|
|
239
|
-
]
|
|
246
|
+
messages: [{ role: "user", content: "What is 15 multiplied by 4?" }],
|
|
240
247
|
});
|
|
241
248
|
// The response.content will likely include the thought process and the tool's output.
|
|
242
249
|
console.log(JSON.stringify(response, null, 2));
|
|
@@ -250,18 +257,16 @@ performCalculation().catch(console.error);
|
|
|
250
257
|
### Multi-Agent Systems
|
|
251
258
|
|
|
252
259
|
```typescript
|
|
253
|
-
import { AgentBuilder } from
|
|
260
|
+
import { AgentBuilder } from "@iqai/adk";
|
|
254
261
|
|
|
255
262
|
// Sequential workflow
|
|
256
|
-
const workflow = await AgentBuilder
|
|
257
|
-
.create("data_pipeline")
|
|
263
|
+
const workflow = await AgentBuilder.create("data_pipeline")
|
|
258
264
|
.asSequential([dataCollector, dataProcessor, dataAnalyzer])
|
|
259
265
|
.withQuickSession("pipeline-app", "admin")
|
|
260
266
|
.build();
|
|
261
267
|
|
|
262
268
|
// Parallel execution
|
|
263
|
-
const parallelAnalysis = await AgentBuilder
|
|
264
|
-
.create("multi_analysis")
|
|
269
|
+
const parallelAnalysis = await AgentBuilder.create("multi_analysis")
|
|
265
270
|
.asParallel([sentimentAnalyzer, topicExtractor, summaryGenerator])
|
|
266
271
|
.build();
|
|
267
272
|
```
|
|
@@ -269,32 +274,32 @@ const parallelAnalysis = await AgentBuilder
|
|
|
269
274
|
### Memory & Sessions
|
|
270
275
|
|
|
271
276
|
```typescript
|
|
272
|
-
import { Agent, InMemorySessionService } from
|
|
277
|
+
import { Agent, InMemorySessionService } from "@iqai/adk";
|
|
273
278
|
|
|
274
279
|
const agent = new LlmAgent({
|
|
275
280
|
name: "persistent_assistant",
|
|
276
281
|
model: "gpt-4-turbo",
|
|
277
282
|
sessionService: new InMemorySessionService(),
|
|
278
|
-
instructions: "Remember our conversation history."
|
|
283
|
+
instructions: "Remember our conversation history.",
|
|
279
284
|
});
|
|
280
285
|
```
|
|
281
286
|
|
|
282
287
|
### Custom Tools
|
|
283
288
|
|
|
284
289
|
```typescript
|
|
285
|
-
import { BaseTool } from
|
|
290
|
+
import { BaseTool } from "@iqai/adk";
|
|
286
291
|
|
|
287
292
|
class WeatherTool extends BaseTool {
|
|
288
293
|
constructor() {
|
|
289
294
|
super({
|
|
290
|
-
name:
|
|
291
|
-
description:
|
|
295
|
+
name: "weather",
|
|
296
|
+
description: "Get current weather information",
|
|
292
297
|
});
|
|
293
298
|
}
|
|
294
299
|
|
|
295
300
|
async runAsync(args: { location: string }) {
|
|
296
301
|
// Implementation here
|
|
297
|
-
return { temperature: 72, condition:
|
|
302
|
+
return { temperature: 72, condition: "sunny" };
|
|
298
303
|
}
|
|
299
304
|
}
|
|
300
305
|
```
|