@iqai/adk 0.6.1 → 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 +20 -33
- 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 +7464 -5362
- package/dist/index.mjs +8582 -6480
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
3
23
|
## 0.6.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -9,7 +29,6 @@
|
|
|
9
29
|
The PluginManager had several callback methods defined but never invoked, causing plugins implementing guardrails, logging, or error recovery to be silently ignored.
|
|
10
30
|
|
|
11
31
|
This fix adds the missing calls for:
|
|
12
|
-
|
|
13
32
|
- `beforeModelCallback` / `afterModelCallback` - intercept LLM requests/responses
|
|
14
33
|
- `onModelErrorCallback` - handle/recover from LLM errors
|
|
15
34
|
- `beforeToolCallback` / `afterToolCallback` - intercept tool execution
|
|
@@ -28,52 +47,44 @@
|
|
|
28
47
|
### ✨ New Features
|
|
29
48
|
|
|
30
49
|
**Modular Architecture**
|
|
31
|
-
|
|
32
50
|
- Refactored from monolithic to service-based design
|
|
33
51
|
- Separate modules for tracing, metrics, setup, and utilities
|
|
34
52
|
- Clean `telemetryService` API replacing low-level functions
|
|
35
53
|
|
|
36
54
|
**Metrics Support**
|
|
37
|
-
|
|
38
55
|
- Full metrics collection with OpenTelemetry SDK
|
|
39
56
|
- Counters: agent invocations, tool executions, LLM calls
|
|
40
57
|
- Histograms: duration tracking, token usage (input/output/total)
|
|
41
58
|
- OTLP HTTP exporter for metrics
|
|
42
59
|
|
|
43
60
|
**Privacy Controls**
|
|
44
|
-
|
|
45
61
|
- `ADK_CAPTURE_MESSAGE_CONTENT` environment variable
|
|
46
62
|
- Fine-grained control over sensitive data capture
|
|
47
63
|
- Disable prompt/completion logging for production
|
|
48
64
|
|
|
49
65
|
**Semantic Conventions**
|
|
50
|
-
|
|
51
66
|
- OpenTelemetry GenAI conventions (v1.37+)
|
|
52
67
|
- ADK-specific namespace (`adk.*`) for custom attributes
|
|
53
68
|
- Standardized attribute names across all spans
|
|
54
69
|
|
|
55
70
|
**Enhanced Tracing**
|
|
56
|
-
|
|
57
71
|
- Automatic agent invocation tracing with status tracking
|
|
58
72
|
- Tool execution spans with arguments and results
|
|
59
73
|
- LLM call tracing with token usage metrics
|
|
60
74
|
- Async generator support for streaming responses
|
|
61
75
|
|
|
62
76
|
**Resource Auto-Detection**
|
|
63
|
-
|
|
64
77
|
- Automatic detection of host, OS, and process information
|
|
65
78
|
- Custom resource attributes support
|
|
66
79
|
- Service instance identification
|
|
67
80
|
|
|
68
81
|
**Configuration**
|
|
69
|
-
|
|
70
82
|
- Comprehensive initialization options
|
|
71
83
|
- Sampling ratio control for production
|
|
72
84
|
- Configurable metric export intervals
|
|
73
85
|
- Custom OTLP headers for authentication
|
|
74
86
|
|
|
75
87
|
### 🔧 Breaking Changes
|
|
76
|
-
|
|
77
88
|
- `initializeTelemetry()` → `telemetryService.initialize()`
|
|
78
89
|
- `shutdownTelemetry()` → `telemetryService.shutdown()`
|
|
79
90
|
- Legacy `telemetry.ts` now wraps new service for backward compatibility
|
|
@@ -81,13 +92,11 @@
|
|
|
81
92
|
### 📊 Integration
|
|
82
93
|
|
|
83
94
|
All core components now automatically report metrics:
|
|
84
|
-
|
|
85
95
|
- `BaseAgent.runAsyncInternal()`: Agent metrics
|
|
86
96
|
- `functions.ts`: Tool execution metrics
|
|
87
97
|
- `base-llm-flow.ts`: LLM token and duration metrics
|
|
88
98
|
|
|
89
99
|
### 📚 Documentation
|
|
90
|
-
|
|
91
100
|
- Comprehensive README in `src/telemetry/`
|
|
92
101
|
- Updated observability example with Jaeger + Langfuse
|
|
93
102
|
- Practical examples demonstrating all features
|
|
@@ -95,12 +104,10 @@
|
|
|
95
104
|
### 🛠️ Technical Details
|
|
96
105
|
|
|
97
106
|
**Dependencies Added**:
|
|
98
|
-
|
|
99
107
|
- `@opentelemetry/sdk-metrics@^2.1.0`
|
|
100
108
|
- `@opentelemetry/exporter-metrics-otlp-http@^0.205.0`
|
|
101
109
|
|
|
102
110
|
**Supported Backends**:
|
|
103
|
-
|
|
104
111
|
- Jaeger (local development)
|
|
105
112
|
- Langfuse
|
|
106
113
|
- Datadog
|
|
@@ -123,14 +130,12 @@
|
|
|
123
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.
|
|
124
131
|
|
|
125
132
|
**Breaking Changes:**
|
|
126
|
-
|
|
127
133
|
- `gen_ai.system` → `gen_ai.provider.name` (automatic provider detection from model names)
|
|
128
134
|
- `gen_ai.usage.total_tokens` removed (compute client-side: input + output)
|
|
129
135
|
- `call_llm` operation deprecated in favor of standard `chat`, `text_completion`, `generate_content`
|
|
130
136
|
- `traceCallback` signature changed: removed unused `targetName` parameter
|
|
131
137
|
|
|
132
138
|
**New Features:**
|
|
133
|
-
|
|
134
139
|
- Automatic provider detection (OpenAI, Anthropic, Google, AWS Bedrock, Mistral, Groq, Cohere, etc.)
|
|
135
140
|
- Enhanced LLM attributes: `response.id`, `response.model`, `output.type`, `top_k`, `frequency_penalty`, `presence_penalty`, `stop_sequences`, `seed`
|
|
136
141
|
- Structured content capture: `system_instructions`, `input.messages`, `output.messages`, `tool.definitions`
|
|
@@ -140,7 +145,6 @@
|
|
|
140
145
|
- Error type tracking: `error.type` attribute for low-cardinality error identification
|
|
141
146
|
|
|
142
147
|
**Backward Compatibility:**
|
|
143
|
-
|
|
144
148
|
- Deprecated constants are still available but will be removed in v1.0.0
|
|
145
149
|
- All `adk.*` namespace attributes remain unchanged
|
|
146
150
|
- Legacy content events preserved for one release cycle
|
|
@@ -152,7 +156,6 @@
|
|
|
152
156
|
### Patch Changes
|
|
153
157
|
|
|
154
158
|
- 27d6bd9: Refactored MCP sampling parameters to align with the official protocol specification by moving from direct model assertions to the `modelPreferences` hint system.
|
|
155
|
-
|
|
156
159
|
- **Protocol Alignment**
|
|
157
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.
|
|
158
161
|
|
|
@@ -177,7 +180,6 @@
|
|
|
177
180
|
- Improved event naming with descriptive suffixes (`.function_call`, `.final_response`, `.event`).
|
|
178
181
|
- Included `finishReason` in event metadata for enhanced execution context and observability.
|
|
179
182
|
- 0ada268: Added full plugin support across the agent lifecycle, enabling interception and extension of agent behavior during execution, model calls, and tool invocations.
|
|
180
|
-
|
|
181
183
|
- Integrated plugin manager into `BaseAgent`, giving plugins priority over canonical callbacks.
|
|
182
184
|
- Added `plugins` configuration to `AgentBuilder` and introduced `withPlugins()` API.
|
|
183
185
|
- Updated `LlmAgent` and `BaseAgent` flows to run plugin lifecycle hooks (`before/after agent`, `before/after model`, `before/after tool`, error hooks, etc.).
|
|
@@ -236,7 +238,6 @@
|
|
|
236
238
|
### Minor Changes
|
|
237
239
|
|
|
238
240
|
- 9c8441c: Enhanced CoinGecko MCP server support with remote endpoints
|
|
239
|
-
|
|
240
241
|
- **Enhanced createMcpConfig function**: Now automatically detects URLs and uses `mcp-remote` for remote MCP endpoints while maintaining backward compatibility with npm packages
|
|
241
242
|
- **Updated McpCoinGecko**: Now uses the remote CoinGecko MCP API endpoint (`https://mcp.api.coingecko.com/mcp`) instead of the npm package
|
|
242
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
|
|
@@ -256,7 +257,6 @@
|
|
|
256
257
|
### Minor Changes
|
|
257
258
|
|
|
258
259
|
- c538a1a: feat(adk): align before/after model callback signatures with runtime (single object arg) and wire before/after tool callbacks into tool execution.
|
|
259
|
-
|
|
260
260
|
- beforeModelCallback/afterModelCallback now receive `{ callbackContext, llmRequest|llmResponse }` to match runtime invocation; removes need for casts in examples.
|
|
261
261
|
- beforeToolCallback/afterToolCallback are now invoked around tool execution; allow argument mutation and result override.
|
|
262
262
|
- tracing updated to include final args and the produced event.
|
|
@@ -297,21 +297,17 @@
|
|
|
297
297
|
### Patch Changes
|
|
298
298
|
|
|
299
299
|
- 2da690a: - **Dependency Updates:**
|
|
300
|
-
|
|
301
300
|
- Upgraded dependencies and devDependencies across multiple packages ensuring compatibility with the latest library versions.
|
|
302
301
|
|
|
303
302
|
- **Schema Handling:**
|
|
304
|
-
|
|
305
303
|
- Transitioned schema conversion to use `z.toJSONSchema`, reducing dependencies.
|
|
306
304
|
- Enhanced type safety in the workflow tool's schema handling.
|
|
307
305
|
|
|
308
306
|
- **Error Reporting and Validation:**
|
|
309
|
-
|
|
310
307
|
- Improved error messages in `AgentBuilder` for better debugging.
|
|
311
308
|
- Enhanced output validation for LLM.
|
|
312
309
|
|
|
313
310
|
- **AI SDK and Model Integration:**
|
|
314
|
-
|
|
315
311
|
- Refined model ID handling in `AiSdkLlm`.
|
|
316
312
|
- Updated field references to align with AI SDK changes.
|
|
317
313
|
|
|
@@ -331,17 +327,14 @@
|
|
|
331
327
|
### Minor Changes
|
|
332
328
|
|
|
333
329
|
- 3561208: ## Features
|
|
334
|
-
|
|
335
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.
|
|
336
331
|
- Improved `AgentBuilder` methods (asSequential, asParallel, and related build methods) for better type propagation and correct return types for multi-agent aggregators.
|
|
337
332
|
- Output schemas can no longer be set directly on multi-agent aggregators. Schemas must now be defined on individual sub-agents.
|
|
338
333
|
|
|
339
334
|
## Fixes
|
|
340
|
-
|
|
341
335
|
- Bugfix in mergeAgentRun that caused incorrect removal of resolved promises.
|
|
342
336
|
|
|
343
337
|
## Changes
|
|
344
|
-
|
|
345
338
|
- `ask()` implementation tailored to aggregate and return per-agent responses for multi-agent setups while maintaining schema validation for single-agent cases.
|
|
346
339
|
- Now, `AgentBuilder` and `BuiltAgent` are being re-exported explicitly from the ADK entrypoint for type preservation in bundled declarations.
|
|
347
340
|
|
|
@@ -392,7 +385,6 @@
|
|
|
392
385
|
This major enhancement improves the ADK CLI server's agent loading capabilities and adds new features to the core framework:
|
|
393
386
|
|
|
394
387
|
**CLI Server Improvements:**
|
|
395
|
-
|
|
396
388
|
- **Modular Architecture**: Refactored monolithic server file into organized modules (`server/index.ts`, `server/routes.ts`, `server/services.ts`, `server/types.ts`)
|
|
397
389
|
- **Enhanced Agent Resolution**: New `resolveAgentExport` method supports multiple export patterns:
|
|
398
390
|
- Direct agent exports: `export const agent = new LlmAgent(...)`
|
|
@@ -403,13 +395,11 @@
|
|
|
403
395
|
- **Improved TypeScript Import Handling**: Better project root detection and module resolution for TypeScript files
|
|
404
396
|
|
|
405
397
|
**Core Framework Enhancements:**
|
|
406
|
-
|
|
407
398
|
- **New AgentBuilder Method**: Added `withAgent()` method to directly provide existing agent instances with definition locking to prevent accidental configuration overwrites
|
|
408
399
|
- **Two-Tier Tool Deduplication**: Implemented robust deduplication logic to prevent duplicate function declarations that cause errors with LLM providers (especially Google)
|
|
409
400
|
- **Better Type Safety**: Improved type definitions and replaced `any[]` usage with proper typed interfaces
|
|
410
401
|
|
|
411
402
|
**Testing & Reliability:**
|
|
412
|
-
|
|
413
403
|
- **Comprehensive Test Coverage**: New `agent-resolution.test.ts` with extensive fixtures testing various agent export patterns
|
|
414
404
|
- **Multiple Test Fixtures**: Added 6 different agent export pattern examples for validation
|
|
415
405
|
- **Edge Case Handling**: Improved error handling and logging throughout the agent loading pipeline
|
|
@@ -419,7 +409,6 @@
|
|
|
419
409
|
- 1564b7b: Port Python evaluation framework to TypeScript
|
|
420
410
|
|
|
421
411
|
This change introduces a comprehensive evaluation framework for testing AI agent performance. Key features include:
|
|
422
|
-
|
|
423
412
|
- **Core evaluation engine** with agent-evaluator and local evaluation service
|
|
424
413
|
- **Built-in evaluators** for response matching, trajectory analysis, LLM-as-judge, and safety checks
|
|
425
414
|
- **Metrics system** with ROUGE scoring and tool trajectory analysis
|
|
@@ -552,14 +541,12 @@
|
|
|
552
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.
|
|
553
542
|
|
|
554
543
|
## Key Features
|
|
555
|
-
|
|
556
544
|
- **AI-SDK Integration**: New `AiSdkLlm` class that integrates with Vercel AI SDK, supporting multiple providers (Google, OpenAI, Anthropic)
|
|
557
545
|
- **Tool Calling Support**: Robust tool calling capabilities with automatic transformation of ADK function declarations to AI SDK tool definitions using Zod schemas
|
|
558
546
|
- **Agent Builder Support**: Enhanced agent builder with AI-SDK model support
|
|
559
547
|
- **Example Implementation**: Complete weather agent example demonstrating AI-SDK usage with tool calling
|
|
560
548
|
|
|
561
549
|
## Technical Details
|
|
562
|
-
|
|
563
550
|
- Adds `ai-sdk.ts` model implementation with streaming support
|
|
564
551
|
- Implements message format conversion between ADK and AI SDK formats
|
|
565
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
|
```
|