@breadstone/archipel-mcp 0.0.54 → 0.0.55
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/data/guides/ai-image-generation.md +96 -0
- package/data/guides/ai-realtime-voice.md +69 -464
- package/data/guides/ai-text-generation.md +95 -626
- package/data/guides/index.md +2 -1
- package/data/guides/intelligence-prompts-warm-up.md +63 -283
- package/data/packages/platform-intelligence/api/Class.AnthropicIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.GatewayIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.GoogleIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.GrokIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceAgent.md +95 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceAgentFactory.md +11 -23
- package/data/packages/platform-intelligence/api/Class.IntelligenceEmbeddingGenerator.md +25 -21
- package/data/packages/platform-intelligence/api/Class.IntelligenceHealthIndicator.md +11 -7
- package/data/packages/platform-intelligence/api/Class.IntelligenceLanguageGenerator.md +159 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceMediaGenerator.md +60 -38
- package/data/packages/platform-intelligence/api/Class.IntelligenceModule.md +2 -2
- package/data/packages/platform-intelligence/api/Class.IntelligencePromptExecutor.md +6 -6
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderAssetUploader.md +21 -15
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderDiagnostics.md +55 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderError.md +14 -4
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderRegistry.md +68 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeError.md +9 -9
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionFactory.md +12 -12
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionPort.md +18 -18
- package/data/packages/platform-intelligence/api/Class.IntelligenceReranker.md +58 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolBase.md +14 -16
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolRegistry.md +10 -14
- package/data/packages/platform-intelligence/api/Class.MiMoIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.OpenAIIntelligenceProviderAdapter.md +102 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicAdvisor20260301Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250522Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250825Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20260120Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20251124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicMemory20250818Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250429Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250728Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchBM2520251119Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchRegex20251119Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20250910Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20260209Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20250305Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20260209Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleCodeExecutionTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleEnterpriseWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleMapsTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleUrlContextTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleVertexRagStoreTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokCodeExecutionTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokMcpServerTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokViewImageTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokViewXVideoTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokXSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createIntelligenceJsonSchema.md +31 -0
- package/data/packages/platform-intelligence/api/Function.createIntelligenceTool.md +2 -2
- package/data/packages/platform-intelligence/api/Function.createMimoCustomTool.md +5 -5
- package/data/packages/platform-intelligence/api/Function.createOpenAIApplyPatchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAICodeInterpreterTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAICustomTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIImageGenerationTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAILocalShellTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIMcpTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIShellTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIToolSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchPreviewTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.defineIntelligenceTool.md +31 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceAgentConfiguration.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingBatchOptions.md +124 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingBatchResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingOptions.md +114 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceFileUploadOptions.md +102 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceFileUploadResult.md +60 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceGeneratedFile.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceGenerationStepStartEvent.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceImageGenerationOptions.md +170 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceImageGenerationResult.md +60 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageCompletion.md +141 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageGenerationOptions.md +234 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageStream.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelReference.md +34 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelRequestOptions.md +52 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelStatus.md +30 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModuleOptions.md +33 -27
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceObjectStream.md +56 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePrompt.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptDefinition.md +14 -14
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptEffectivePolicy.md +1 -1
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionPolicy.md +1 -1
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionResult.md +15 -27
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderAdapter.md +73 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderConfiguration.md +10 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderLoadRequest.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderProbeResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeModuleOptions.md +9 -21
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeSessionOptions.md +11 -11
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRequestOptions.md +98 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRerankingOptions.md +140 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRerankingResult.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSkillUploadOptions.md +94 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSkillUploadResult.md +80 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSpeechGenerationOptions.md +164 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSpeechGenerationResult.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceStreamingTranscriptionOptions.md +139 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTool.md +7 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolCall.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolDefinition.md +91 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolExecutionEndEvent.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolExecutionStartEvent.md +30 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolRegistry.md +4 -4
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionOptions.md +114 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionResult.md +84 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionStream.md +97 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceUsage.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceVideoGenerationOptions.md +229 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceVideoGenerationResult.md +50 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligenceModelMessage.md +43 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligencePromptModelRequirement.md +2 -2
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligenceSchema.md +70 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceCapability.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceDefaultModels.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceJsonValue.md +22 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptDefinitionConfiguration.md +2 -2
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptGenerationOptions.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderName.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderOptions.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderProbeStatus.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderToolOptions.md +17 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeMeteringEvent.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRequestTimeouts.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolChoice.md +21 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolOutput.md +22 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolSet.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceTranscriptionStreamPart.md +46 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_API_KEY.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_BASE_URL.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MAX_OUTPUT_TOKENS.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MODEL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_PROVIDER.md +2 -2
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TEMPERATURE.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TOP_P.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.IntelligenceCapabilityNames.md +40 -0
- package/data/packages/platform-intelligence/api/Variable.IntelligenceProviderNames.md +2 -0
- package/data/packages/platform-intelligence/api/Variable.PLATFORM_INTELLIGENCE_CONFIG_ENTRIES.md +1 -1
- package/data/packages/platform-intelligence/api/index.md +78 -30
- package/package.json +1 -1
- package/data/packages/index.md +0 -8
- package/data/packages/platform-analytics/index.md +0 -209
- package/data/packages/platform-authentication/index.md +0 -725
- package/data/packages/platform-blob-storage/index.md +0 -416
- package/data/packages/platform-bootstrap/index.md +0 -162
- package/data/packages/platform-caching/index.md +0 -167
- package/data/packages/platform-configuration/index.md +0 -226
- package/data/packages/platform-core/index.md +0 -504
- package/data/packages/platform-cryptography/index.md +0 -142
- package/data/packages/platform-database/index.md +0 -337
- package/data/packages/platform-documents/index.md +0 -255
- package/data/packages/platform-esigning/index.md +0 -710
- package/data/packages/platform-feature-flags/index.md +0 -103
- package/data/packages/platform-health/index.md +0 -141
- package/data/packages/platform-intelligence/api/Class.IntelligenceStructuredGenerator.md +0 -70
- package/data/packages/platform-intelligence/api/Class.IntelligenceTelemetryRegistry.md +0 -44
- package/data/packages/platform-intelligence/api/Class.IntelligenceTextGenerator.md +0 -138
- package/data/packages/platform-intelligence/api/Function.createProviderOptions.md +0 -39
- package/data/packages/platform-intelligence/api/Function.loadAnthropicLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGoogleLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGoogleRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Function.loadGrokLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGrokRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Function.loadMimoLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadOpenAILanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadOpenAIRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCompletionUsage.md +0 -46
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextCompletion.md +0 -180
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerationOptions.md +0 -144
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerator.md +0 -78
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextStreamingOptions.md +0 -170
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoader.md +0 -24
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoaders.md +0 -14
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoader.md +0 -25
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoaders.md +0 -14
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceTextStream.md +0 -14
- package/data/packages/platform-intelligence/index.md +0 -627
- package/data/packages/platform-logging/index.md +0 -150
- package/data/packages/platform-mailing/index.md +0 -470
- package/data/packages/platform-mapping/index.md +0 -123
- package/data/packages/platform-mcp/index.md +0 -335
- package/data/packages/platform-openapi/index.md +0 -207
- package/data/packages/platform-payments/index.md +0 -610
- package/data/packages/platform-queue/index.md +0 -192
- package/data/packages/platform-reporting/index.md +0 -233
- package/data/packages/platform-resources/index.md +0 -137
- package/data/packages/platform-telemetry/index.md +0 -262
|
@@ -1,687 +1,156 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: AI
|
|
3
|
-
description: Generate text
|
|
2
|
+
title: AI Language Generation
|
|
3
|
+
description: Generate text and structured output, stream results, use tools, and create agents without leaking provider SDKs.
|
|
4
4
|
order: 15
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
# AI
|
|
7
|
+
# AI Language Generation
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
`IntelligenceLanguageGenerator` is the provider-neutral language facade. It
|
|
10
|
+
owns plain text, schema-constrained objects, streaming, tool execution, result
|
|
11
|
+
normalization, retries, cancellation, and timeouts.
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
execution policy, and a NestJS executor, start with
|
|
13
|
-
[Intelligence Prompts Warm-up](./intelligence-prompts-warm-up).
|
|
14
|
-
|
|
15
|
-
For server-owned, bidirectional audio and text connections, use the separate
|
|
16
|
-
[AI Realtime Voice](./ai-realtime-voice) guide. Realtime sessions have a
|
|
17
|
-
different transport, lifecycle, persistence, and metering model from request-
|
|
18
|
-
or response-scoped text generation.
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
13
|
+
Consumer applications depend only on Archipel:
|
|
23
14
|
|
|
24
15
|
```bash
|
|
25
16
|
yarn add @breadstone/archipel-platform-intelligence
|
|
26
17
|
```
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| Provider | Package |
|
|
31
|
-
| -------------- | ------------------- |
|
|
32
|
-
| **OpenAI** | `@ai-sdk/openai` |
|
|
33
|
-
| **Anthropic** | `@ai-sdk/anthropic` |
|
|
34
|
-
| **Google** | `@ai-sdk/google` |
|
|
35
|
-
| **Grok (xAI)** | `@ai-sdk/xai` |
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# Example: OpenAI
|
|
39
|
-
yarn add @ai-sdk/openai
|
|
40
|
-
|
|
41
|
-
# Example: Grok / xAI
|
|
42
|
-
yarn add @ai-sdk/xai
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Module Registration
|
|
48
|
-
|
|
49
|
-
Import `IntelligenceModule` into your application module. It exposes `IntelligenceTextGenerator` and `IntelligenceToolRegistry` as shared providers.
|
|
19
|
+
## Registration
|
|
50
20
|
|
|
51
21
|
```typescript
|
|
52
22
|
import { Module } from '@nestjs/common';
|
|
53
|
-
import {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
],
|
|
64
|
-
})
|
|
65
|
-
export class AppModule {}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Register only the provider loaders you install. The root entry does not import provider SDK packages.
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## Configuration
|
|
73
|
-
|
|
74
|
-
All intelligence settings are read from environment variables via `ConfigService`. No direct `process.env` access is needed.
|
|
75
|
-
|
|
76
|
-
```dotenv
|
|
77
|
-
INTELLIGENCE_PROVIDER=openai
|
|
78
|
-
INTELLIGENCE_MODEL=gpt-4o-mini
|
|
79
|
-
INTELLIGENCE_API_KEY=sk-...
|
|
80
|
-
INTELLIGENCE_TEMPERATURE=0.7
|
|
81
|
-
INTELLIGENCE_TOP_P=1
|
|
82
|
-
INTELLIGENCE_MAX_OUTPUT_TOKENS=1024
|
|
83
|
-
INTELLIGENCE_BASE_URL= # optional — override for custom endpoints
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Supported Providers
|
|
87
|
-
|
|
88
|
-
| `INTELLIGENCE_PROVIDER` | Default model | Notes |
|
|
89
|
-
| ----------------------- | -------------------------- | ---------------------------------- |
|
|
90
|
-
| `openai` | `gpt-4o-mini` | OpenAI API |
|
|
91
|
-
| `anthropic` | `claude-sonnet-4-20250514` | Anthropic API |
|
|
92
|
-
| `google` | `gemini-2.0-flash` | Google Gemini API |
|
|
93
|
-
| `grok` | `grok-3-mini` | xAI Grok API |
|
|
94
|
-
|
|
95
|
-
Each provider resolves its API key and base URL from dedicated environment variables when the generic `INTELLIGENCE_API_KEY` is not set:
|
|
96
|
-
|
|
97
|
-
```dotenv
|
|
98
|
-
# Provider-specific keys (optional — fallback from INTELLIGENCE_API_KEY)
|
|
99
|
-
OPENAI_API_KEY=sk-...
|
|
100
|
-
ANTHROPIC_API_KEY=sk-ant-...
|
|
101
|
-
GOOGLE_API_KEY=AI...
|
|
102
|
-
GROK_API_KEY=xai-...
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## Generating Text
|
|
108
|
-
|
|
109
|
-
Inject `IntelligenceTextGenerator` to generate completions:
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
import { Injectable } from '@nestjs/common';
|
|
113
|
-
import type { Prompt } from 'ai';
|
|
114
|
-
import { IntelligenceTextGenerator, type IIntelligenceTextCompletion } from '@breadstone/archipel-platform-intelligence';
|
|
115
|
-
|
|
116
|
-
@Injectable()
|
|
117
|
-
export class SummaryService {
|
|
118
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
119
|
-
|
|
120
|
-
constructor(textGenerator: IntelligenceTextGenerator) {
|
|
121
|
-
this._textGenerator = textGenerator;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public async summarize(content: string): Promise<string> {
|
|
125
|
-
const prompt: Prompt = {
|
|
126
|
-
system: 'You are a concise summarizer. Respond with a short summary.',
|
|
127
|
-
messages: [{ role: 'user', content: content }],
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const completion = await this._textGenerator.generateText(prompt);
|
|
131
|
-
|
|
132
|
-
return completion.text;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Prompt Structure
|
|
138
|
-
|
|
139
|
-
A prompt uses the native AI SDK `Prompt` type. Use either a string prompt or a full message array:
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
type Prompt =
|
|
143
|
-
| { readonly system?: string; readonly prompt: string }
|
|
144
|
-
| { readonly system?: string; readonly messages: Array<ModelMessage> };
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Per-Request Overrides
|
|
148
|
-
|
|
149
|
-
Override generation parameters for individual requests without changing the global configuration:
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
const completion = await this._textGenerator.generateText(prompt, {
|
|
153
|
-
temperature: 0.2, // more deterministic
|
|
154
|
-
maxOutputTokens: 256, // shorter responses
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### Completion Response
|
|
159
|
-
|
|
160
|
-
The response includes the generated text, the provider/model used, provider-native sources, generated files, and optional token usage telemetry:
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
interface IIntelligenceTextCompletion {
|
|
164
|
-
readonly text: string;
|
|
165
|
-
readonly provider: string;
|
|
166
|
-
readonly model: string;
|
|
167
|
-
readonly sources: ReadonlyArray<LanguageModelV3Source>;
|
|
168
|
-
readonly files: ReadonlyArray<GeneratedFile>;
|
|
169
|
-
readonly usage: IIntelligenceCompletionUsage | null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
interface IIntelligenceCompletionUsage {
|
|
173
|
-
readonly promptTokens: number | null;
|
|
174
|
-
readonly completionTokens: number | null;
|
|
175
|
-
readonly totalTokens: number | null;
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## Multi-Turn Conversations
|
|
182
|
-
|
|
183
|
-
Build multi-turn conversations by passing the full message history:
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
const prompt: Prompt = {
|
|
187
|
-
system: 'You are a helpful fitness coach.',
|
|
188
|
-
messages: [
|
|
189
|
-
{ role: 'user', content: 'What should I eat before a workout?' },
|
|
190
|
-
{ role: 'assistant', content: 'A balanced meal with carbs and protein about 2 hours before.' },
|
|
191
|
-
{ role: 'user', content: 'Can you give me a specific example?' },
|
|
192
|
-
],
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const completion = await this._textGenerator.generateText(prompt);
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## Tool Registration
|
|
201
|
-
|
|
202
|
-
The intelligence module uses native AI SDK tools. Define a class that exposes a `name` and a native `Tool`, or register provider-native tool wrappers from provider subpaths.
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
import { Injectable, Module } from '@nestjs/common';
|
|
206
|
-
import { tool, type Tool } from 'ai';
|
|
207
|
-
import { z } from 'zod';
|
|
208
|
-
import { IntelligenceModule, IntelligenceProviderNames, IntelligenceToolBase } from '@breadstone/archipel-platform-intelligence';
|
|
209
|
-
import { loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
210
|
-
|
|
211
|
-
interface IWorkoutInput {
|
|
212
|
-
readonly goal: string;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
interface IWorkoutOutput {
|
|
216
|
-
readonly recommendation: string;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
@Injectable()
|
|
220
|
-
export class WorkoutRecommendationTool extends IntelligenceToolBase<IWorkoutInput, IWorkoutOutput> {
|
|
221
|
-
public override get name(): string {
|
|
222
|
-
return 'recommendWorkout';
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
public override get tool(): Tool<IWorkoutInput, IWorkoutOutput> {
|
|
226
|
-
return tool({
|
|
227
|
-
description: 'Recommends a workout plan for a user goal.',
|
|
228
|
-
inputSchema: z.object({
|
|
229
|
-
goal: z.string().describe('The user fitness goal'),
|
|
230
|
-
}),
|
|
231
|
-
execute: async (input) => ({
|
|
232
|
-
recommendation: `Workout plan for ${input.goal}`,
|
|
233
|
-
}),
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
23
|
+
import {
|
|
24
|
+
IntelligenceCapabilityNames,
|
|
25
|
+
IntelligenceModule,
|
|
26
|
+
IntelligenceProviderNames,
|
|
27
|
+
} from '@breadstone/archipel-platform-intelligence';
|
|
28
|
+
import { AnthropicIntelligenceProviderAdapter } from '@breadstone/archipel-platform-intelligence/anthropic';
|
|
29
|
+
import { OpenAIIntelligenceProviderAdapter } from '@breadstone/archipel-platform-intelligence/openai';
|
|
237
30
|
|
|
238
31
|
@Module({
|
|
239
32
|
imports: [
|
|
240
33
|
IntelligenceModule.register({
|
|
241
|
-
|
|
242
|
-
|
|
34
|
+
providerAdapters: [
|
|
35
|
+
new OpenAIIntelligenceProviderAdapter(),
|
|
36
|
+
new AnthropicIntelligenceProviderAdapter(),
|
|
37
|
+
],
|
|
38
|
+
defaultModels: {
|
|
39
|
+
[IntelligenceCapabilityNames.Language]: {
|
|
40
|
+
provider: IntelligenceProviderNames.OpenAI,
|
|
41
|
+
model: 'gpt-5.4-mini',
|
|
42
|
+
},
|
|
243
43
|
},
|
|
244
|
-
tools: [WorkoutRecommendationTool],
|
|
245
44
|
}),
|
|
246
45
|
],
|
|
247
46
|
})
|
|
248
|
-
export class
|
|
47
|
+
export class ApplicationModule {}
|
|
249
48
|
```
|
|
250
49
|
|
|
251
|
-
|
|
50
|
+
## Text and Objects
|
|
252
51
|
|
|
253
52
|
```typescript
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
53
|
+
const completion = await language.generateText(
|
|
54
|
+
{
|
|
55
|
+
system: 'Answer using the supplied application context only.',
|
|
56
|
+
prompt: 'Summarize the open tasks.',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
maxOutputTokens: 800,
|
|
60
|
+
maxRetries: 2,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
258
63
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}),
|
|
267
|
-
],
|
|
268
|
-
})
|
|
269
|
-
export class SearchModule {}
|
|
64
|
+
const structured = await language.generateObject(
|
|
65
|
+
{ prompt: 'Classify the customer request.' },
|
|
66
|
+
z.object({
|
|
67
|
+
category: z.enum(['billing', 'technical', 'other']),
|
|
68
|
+
urgency: z.enum(['low', 'normal', 'high']),
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
270
71
|
```
|
|
271
72
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
73
|
+
Applications can provide a model override as
|
|
74
|
+
`{ provider: string, model: string }`. They never construct a provider-native
|
|
75
|
+
model.
|
|
275
76
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
Use the native AI SDK prompt shape for prompt strings, multimodal `ModelMessage` arrays, system-message arrays, or other prompt forms supported by the AI SDK.
|
|
77
|
+
## Streaming
|
|
279
78
|
|
|
280
79
|
```typescript
|
|
281
|
-
|
|
282
|
-
import { Injectable, Module } from '@nestjs/common';
|
|
283
|
-
import { IntelligenceModule, IntelligenceTextGenerator, type IIntelligenceTextCompletion } from '@breadstone/archipel-platform-intelligence';
|
|
284
|
-
|
|
285
|
-
@Module({
|
|
286
|
-
imports: [
|
|
287
|
-
IntelligenceModule.register({
|
|
288
|
-
validateOnModuleInit: false,
|
|
289
|
-
}),
|
|
290
|
-
],
|
|
291
|
-
})
|
|
292
|
-
export class RawAiSdkModule {}
|
|
293
|
-
|
|
294
|
-
@Injectable()
|
|
295
|
-
export class RawAiSdkRecipeService {
|
|
296
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
297
|
-
|
|
298
|
-
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
299
|
-
this._textGenerator = textGenerator;
|
|
300
|
-
}
|
|
80
|
+
const stream = await language.streamText({ prompt: 'Explain the result.' });
|
|
301
81
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
{
|
|
305
|
-
system: 'Answer concisely and include assumptions.',
|
|
306
|
-
prompt: 'Compare the operational risks of outdoor work tomorrow.',
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
model: openai.responses('gpt-5'),
|
|
310
|
-
headers: { 'x-use-case': 'outdoor-risk' },
|
|
311
|
-
providerOptions: {
|
|
312
|
-
openai: {
|
|
313
|
-
reasoningEffort: 'medium',
|
|
314
|
-
},
|
|
315
|
-
},
|
|
316
|
-
seed: 42,
|
|
317
|
-
},
|
|
318
|
-
);
|
|
319
|
-
}
|
|
82
|
+
for await (const delta of stream.textStream) {
|
|
83
|
+
sendToAuthenticatedClient(delta);
|
|
320
84
|
}
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
If every request passes a native AI SDK model, `validateOnModuleInit: false` avoids requiring platform provider configuration at startup. If no `model` option is supplied, the configured provider loader and `INTELLIGENCE_PROVIDER` / `INTELLIGENCE_MODEL` values still define the model.
|
|
324
|
-
|
|
325
|
-
### Additional OpenAI Tool Recipes
|
|
326
85
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
import { Injectable } from '@nestjs/common';
|
|
331
|
-
import { stepCountIs, tool } from 'ai';
|
|
332
|
-
import { z } from 'zod';
|
|
333
|
-
import { IntelligenceTextGenerator } from '@breadstone/archipel-platform-intelligence';
|
|
334
|
-
import { OpenAIIntelligenceToolNames } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
335
|
-
import {
|
|
336
|
-
createOpenAICodeInterpreterTool,
|
|
337
|
-
createOpenAICustomTool,
|
|
338
|
-
createOpenAIImageGenerationTool,
|
|
339
|
-
createOpenAIToolSearchTool,
|
|
340
|
-
} from '@breadstone/archipel-platform-intelligence/providers/openai/tools';
|
|
341
|
-
|
|
342
|
-
@Injectable()
|
|
343
|
-
export class OpenAIToolRecipeService {
|
|
344
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
345
|
-
|
|
346
|
-
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
347
|
-
this._textGenerator = textGenerator;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
public async analyseSpreadsheet(fileId: string): Promise<IIntelligenceTextCompletion> {
|
|
351
|
-
return this._textGenerator.generateText(
|
|
352
|
-
{
|
|
353
|
-
system: 'You analyze uploaded spreadsheets and explain unusual values clearly.',
|
|
354
|
-
messages: [
|
|
355
|
-
{
|
|
356
|
-
role: 'user',
|
|
357
|
-
content: 'Analyze the file, detect unusual values, and summarize the most important findings as a table.',
|
|
358
|
-
},
|
|
359
|
-
],
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
activeTools: [OpenAIIntelligenceToolNames.CodeInterpreter],
|
|
363
|
-
tools: {
|
|
364
|
-
[OpenAIIntelligenceToolNames.CodeInterpreter]: createOpenAICodeInterpreterTool({
|
|
365
|
-
container: { fileIds: [fileId] },
|
|
366
|
-
}).tool,
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
public async generateIllustration(description: string): Promise<IIntelligenceTextCompletion> {
|
|
373
|
-
return this._textGenerator.generateText(
|
|
374
|
-
{
|
|
375
|
-
prompt: description,
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
activeTools: [OpenAIIntelligenceToolNames.ImageGeneration],
|
|
379
|
-
tools: {
|
|
380
|
-
[OpenAIIntelligenceToolNames.ImageGeneration]: createOpenAIImageGenerationTool({
|
|
381
|
-
quality: 'medium',
|
|
382
|
-
size: '1024x1024',
|
|
383
|
-
}).tool,
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
public async answerWithDeferredTools(prompt: string): Promise<IIntelligenceTextCompletion> {
|
|
390
|
-
return this._textGenerator.generateText(
|
|
391
|
-
{
|
|
392
|
-
prompt: prompt,
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
stopWhen: stepCountIs(10),
|
|
396
|
-
tools: {
|
|
397
|
-
[OpenAIIntelligenceToolNames.ToolSearch]: createOpenAIToolSearchTool().tool,
|
|
398
|
-
get_birthdays: tool({
|
|
399
|
-
description: 'Returns employee birthdays in a date range.',
|
|
400
|
-
inputSchema: z.object({
|
|
401
|
-
from: z.string(),
|
|
402
|
-
to: z.string(),
|
|
403
|
-
}),
|
|
404
|
-
execute: async (input) => ({ from: input.from, to: input.to, employees: [] }),
|
|
405
|
-
providerOptions: {
|
|
406
|
-
openai: { deferLoading: true },
|
|
407
|
-
},
|
|
408
|
-
}),
|
|
409
|
-
search_orders: tool({
|
|
410
|
-
description: 'Searches orders using domain-specific filters.',
|
|
411
|
-
inputSchema: z.object({
|
|
412
|
-
query: z.string(),
|
|
413
|
-
}),
|
|
414
|
-
execute: async (input) => ({ query: input.query, orders: [] }),
|
|
415
|
-
providerOptions: {
|
|
416
|
-
openai: { deferLoading: true },
|
|
417
|
-
},
|
|
418
|
-
}),
|
|
419
|
-
},
|
|
420
|
-
},
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
public async createReadOnlyReportQuery(prompt: string): Promise<IIntelligenceTextCompletion> {
|
|
425
|
-
return this._textGenerator.generateText(
|
|
426
|
-
{
|
|
427
|
-
system: 'Create only read-only reporting queries. The query must start with SELECT.',
|
|
428
|
-
messages: [{ role: 'user', content: prompt }],
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
toolChoice: 'required',
|
|
432
|
-
stopWhen: stepCountIs(3),
|
|
433
|
-
activeTools: ['report_query'],
|
|
434
|
-
tools: {
|
|
435
|
-
report_query: createOpenAICustomTool({
|
|
436
|
-
name: 'report_query',
|
|
437
|
-
description: 'Create a strictly read-only reporting query.',
|
|
438
|
-
format: {
|
|
439
|
-
type: 'grammar',
|
|
440
|
-
syntax: 'regex',
|
|
441
|
-
definition: 'SELECT .+',
|
|
442
|
-
},
|
|
443
|
-
}).tool,
|
|
444
|
-
},
|
|
445
|
-
},
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
86
|
+
const finalText = await stream.text;
|
|
87
|
+
const usage = await stream.usage;
|
|
449
88
|
```
|
|
450
89
|
|
|
451
|
-
`
|
|
452
|
-
|
|
453
|
-
|
|
90
|
+
`streamObject()` exposes partial structured output and a validated final object.
|
|
91
|
+
All stream iterables and result promises normalize provider failures as
|
|
92
|
+
`IntelligenceProviderError`.
|
|
454
93
|
|
|
455
|
-
|
|
94
|
+
## Application Tools
|
|
456
95
|
|
|
457
96
|
```typescript
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
IntelligenceModule,
|
|
463
|
-
IntelligenceProviderNames,
|
|
464
|
-
IntelligenceTextGenerator,
|
|
465
|
-
IntelligenceToolBase,
|
|
466
|
-
type IIntelligenceTextCompletion,
|
|
467
|
-
} from '@breadstone/archipel-platform-intelligence';
|
|
468
|
-
import { OpenAIIntelligenceToolNames, loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
469
|
-
import { createOpenAIWebSearchTool } from '@breadstone/archipel-platform-intelligence/providers/openai/tools';
|
|
470
|
-
|
|
471
|
-
interface IOutdoorOrderLookupInput {
|
|
472
|
-
readonly date: string;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
interface IOutdoorOrder {
|
|
476
|
-
readonly id: string;
|
|
477
|
-
readonly location: string;
|
|
478
|
-
readonly scheduledAt: string;
|
|
479
|
-
readonly outdoorWork: boolean;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
interface IOutdoorOrderLookupOutput {
|
|
483
|
-
readonly date: string;
|
|
484
|
-
readonly orders: ReadonlyArray<IOutdoorOrder>;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
@Injectable()
|
|
488
|
-
export class OutdoorOrdersTool extends IntelligenceToolBase<IOutdoorOrderLookupInput, IOutdoorOrderLookupOutput> {
|
|
97
|
+
export class CustomerSearchTool extends IntelligenceToolBase<
|
|
98
|
+
ICustomerSearchInput,
|
|
99
|
+
ReadonlyArray<ICustomerSummary>
|
|
100
|
+
> {
|
|
489
101
|
public override get name(): string {
|
|
490
|
-
return '
|
|
102
|
+
return 'customer_search';
|
|
491
103
|
}
|
|
492
104
|
|
|
493
|
-
public override get tool()
|
|
494
|
-
return
|
|
495
|
-
description: '
|
|
496
|
-
inputSchema:
|
|
497
|
-
|
|
105
|
+
public override get tool() {
|
|
106
|
+
return defineIntelligenceTool({
|
|
107
|
+
description: 'Searches customers visible to the authenticated tenant.',
|
|
108
|
+
inputSchema: createIntelligenceJsonSchema<ICustomerSearchInput>({
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: { query: { type: 'string' } },
|
|
111
|
+
required: ['query'],
|
|
112
|
+
additionalProperties: false,
|
|
498
113
|
}),
|
|
499
|
-
execute: async (
|
|
114
|
+
execute: async ({ query }) => this._customers.search(query),
|
|
500
115
|
});
|
|
501
116
|
}
|
|
502
|
-
|
|
503
|
-
private async loadOutdoorOrders(date: string): Promise<IOutdoorOrderLookupOutput> {
|
|
504
|
-
return {
|
|
505
|
-
date: date,
|
|
506
|
-
orders: [
|
|
507
|
-
{
|
|
508
|
-
id: 'ord_4711',
|
|
509
|
-
location: 'Berlin',
|
|
510
|
-
scheduledAt: `${date}T08:00:00+02:00`,
|
|
511
|
-
outdoorWork: true,
|
|
512
|
-
},
|
|
513
|
-
],
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
117
|
}
|
|
517
|
-
|
|
518
|
-
@Injectable()
|
|
519
|
-
export class OutdoorOrderRiskAnalysisService {
|
|
520
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
521
|
-
|
|
522
|
-
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
523
|
-
this._textGenerator = textGenerator;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
public async analyseOutdoorOrders(date: string): Promise<{ readonly text: string; readonly sources: IIntelligenceTextCompletion['sources'] }> {
|
|
527
|
-
const result = await this._textGenerator.generateText(
|
|
528
|
-
{
|
|
529
|
-
system: 'You assess weather-related risks for tenant outdoor field orders.',
|
|
530
|
-
messages: [
|
|
531
|
-
{
|
|
532
|
-
role: 'user',
|
|
533
|
-
content: `Review outdoor field orders for ${date} and flag weather-related risks.`,
|
|
534
|
-
},
|
|
535
|
-
],
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
toolChoice: 'auto',
|
|
539
|
-
activeTools: ['get_outdoor_orders', OpenAIIntelligenceToolNames.WebSearch],
|
|
540
|
-
stopWhen: stepCountIs(3),
|
|
541
|
-
},
|
|
542
|
-
);
|
|
543
|
-
|
|
544
|
-
return {
|
|
545
|
-
text: result.text,
|
|
546
|
-
sources: result.sources,
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
@Module({
|
|
552
|
-
imports: [
|
|
553
|
-
IntelligenceModule.register({
|
|
554
|
-
providerLoaders: {
|
|
555
|
-
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
556
|
-
},
|
|
557
|
-
tools: [
|
|
558
|
-
OutdoorOrdersTool,
|
|
559
|
-
createOpenAIWebSearchTool({
|
|
560
|
-
externalWebAccess: true,
|
|
561
|
-
searchContextSize: 'medium',
|
|
562
|
-
filters: {
|
|
563
|
-
allowedDomains: ['dwd.de'],
|
|
564
|
-
},
|
|
565
|
-
}),
|
|
566
|
-
],
|
|
567
|
-
}),
|
|
568
|
-
],
|
|
569
|
-
providers: [OutdoorOrderRiskAnalysisService],
|
|
570
|
-
})
|
|
571
|
-
export class OutdoorOrderRiskAnalysisModule {}
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
Use AI SDK request options to constrain tool use per call:
|
|
575
|
-
|
|
576
|
-
```typescript
|
|
577
|
-
const completion = await this._textGenerator.generateText(prompt, {
|
|
578
|
-
toolChoice: 'auto',
|
|
579
|
-
activeTools: ['recommendWorkout'],
|
|
580
|
-
});
|
|
581
118
|
```
|
|
582
119
|
|
|
583
|
-
|
|
120
|
+
Register tools through `IntelligenceModule.register({ tools: [...] })`. Use
|
|
121
|
+
`activeToolNames` to constrain a call and `maxSteps` to bound the tool loop.
|
|
122
|
+
Tool authorization remains application-owned and must fail closed before data
|
|
123
|
+
or side effects are exposed.
|
|
584
124
|
|
|
585
|
-
|
|
125
|
+
Provider-owned tools are imported from Archipel provider `/tools` subpaths.
|
|
126
|
+
They are represented by opaque Archipel definitions; their native SDK types do
|
|
127
|
+
not cross into the application.
|
|
586
128
|
|
|
587
|
-
##
|
|
129
|
+
## Agents
|
|
588
130
|
|
|
589
|
-
`
|
|
131
|
+
`IntelligenceAgentFactory.create()` builds a reusable bounded agent on the same
|
|
132
|
+
language facade:
|
|
590
133
|
|
|
591
134
|
```typescript
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
135
|
+
const agent = agents.create({
|
|
136
|
+
name: 'researcher',
|
|
137
|
+
instructions: 'Use approved sources and report uncertainty.',
|
|
138
|
+
activeToolNames: ['web_search', 'document_search'],
|
|
139
|
+
maxSteps: 6,
|
|
595
140
|
});
|
|
596
141
|
|
|
597
|
-
|
|
142
|
+
const answer = await agent.generate({ prompt: question });
|
|
598
143
|
```
|
|
599
144
|
|
|
600
|
-
|
|
145
|
+
Agents do not create a second provider abstraction. They compose language,
|
|
146
|
+
tools, model policy, and step limits already owned by Archipel.
|
|
601
147
|
|
|
602
|
-
##
|
|
148
|
+
## Results and Failures
|
|
603
149
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
const config = this._textGenerator.getConfiguration();
|
|
608
|
-
console.log(config.provider); // 'openai'
|
|
609
|
-
console.log(config.model); // 'gpt-4o-mini'
|
|
610
|
-
```
|
|
150
|
+
Language completions expose provider, model, text, typed output, finish reason,
|
|
151
|
+
reasoning text, normalized sources and files, tool calls/results, warnings, and
|
|
152
|
+
usage. The default total-operation timeout is 30 seconds.
|
|
611
153
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
`IntelligenceTextGenerator` wraps all provider errors in `IntelligenceProviderError`, which includes `provider`, `model`, and `retryable` metadata. The generator automatically retries retryable failures (e.g. transient network errors) with exponential backoff before giving up.
|
|
617
|
-
|
|
618
|
-
Two additional error classes handle configuration and validation failures:
|
|
619
|
-
|
|
620
|
-
| Error class | Code | When thrown |
|
|
621
|
-
| ---------------------------------- | ----------------------------- | --------------------------------------------------------------------- |
|
|
622
|
-
| `IntelligenceProviderError` | `INTELLIGENCE_PROVIDER` | Provider SDK failures during text generation |
|
|
623
|
-
| `IntelligenceValidationError` | `INTELLIGENCE_VALIDATION` | Invalid generation parameters (temperature, topP, maxOutputTokens) |
|
|
624
|
-
| `IntelligenceConfigurationError` | `INTELLIGENCE_CONFIGURATION` | Unsupported provider, missing API key, or missing provider loader |
|
|
625
|
-
|
|
626
|
-
### Timeout & Retry Defaults
|
|
627
|
-
|
|
628
|
-
| Setting | Default | Description |
|
|
629
|
-
| ----------- | -------- | ----------------------------------------------------------- |
|
|
630
|
-
| `timeoutMs` | `30000` | Abort the provider request after this many milliseconds |
|
|
631
|
-
| Max retries | `2` | Retryable errors are retried up to 2 times |
|
|
632
|
-
| Backoff | 1s → 4s | Exponential backoff with a 4-second cap between retries |
|
|
633
|
-
|
|
634
|
-
Override the timeout per call:
|
|
635
|
-
|
|
636
|
-
```typescript
|
|
637
|
-
const result = await this._textGenerator.generateText(prompt, {
|
|
638
|
-
timeoutMs: 15_000, // 15-second timeout for this call
|
|
639
|
-
});
|
|
640
|
-
```
|
|
641
|
-
|
|
642
|
-
### Catching Errors
|
|
643
|
-
|
|
644
|
-
```typescript
|
|
645
|
-
import { IntelligenceProviderError } from '@breadstone/archipel-platform-intelligence';
|
|
646
|
-
|
|
647
|
-
try {
|
|
648
|
-
const result = await this._textGenerator.generateText(prompt);
|
|
649
|
-
return result.text;
|
|
650
|
-
} catch (error) {
|
|
651
|
-
if (error instanceof IntelligenceProviderError) {
|
|
652
|
-
this._logger.error(`Provider ${error.provider}/${error.model} failed`, {
|
|
653
|
-
retryable: error.retryable,
|
|
654
|
-
message: error.message,
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
return 'Sorry, I could not generate a response right now.';
|
|
658
|
-
}
|
|
659
|
-
```
|
|
660
|
-
|
|
661
|
-
If no loader is registered for the configured provider, startup fails with a clear configuration error. If a provider subpath is imported without its AI SDK peer package installed, the application fails at that import boundary instead of pulling the provider through the root package.
|
|
662
|
-
|
|
663
|
-
---
|
|
664
|
-
|
|
665
|
-
## Architecture Overview
|
|
666
|
-
|
|
667
|
-
```mermaid
|
|
668
|
-
flowchart TB
|
|
669
|
-
subgraph IntelligenceModule[IntelligenceModule]
|
|
670
|
-
TextGenerator[IntelligenceTextGenerator\nConfigService -> provider]
|
|
671
|
-
ToolRegistry[IntelligenceToolRegistry]
|
|
672
|
-
end
|
|
673
|
-
|
|
674
|
-
GenerateText["generateText(prompt, options?)"]
|
|
675
|
-
StreamText["streamText(prompt, options?)"]
|
|
676
|
-
ResolveTools["toToolSet()\nregister(tool)"]
|
|
677
|
-
ProviderLoaders[Registered Provider Loaders\nproviders/openai, providers/anthropic, providers/google, providers/grok]
|
|
678
|
-
FeatureTools[Feature Tools\nnative AI SDK tools]
|
|
679
|
-
|
|
680
|
-
TextGenerator --> GenerateText
|
|
681
|
-
TextGenerator --> StreamText
|
|
682
|
-
ToolRegistry --> ResolveTools
|
|
683
|
-
TextGenerator --> ProviderLoaders
|
|
684
|
-
ToolRegistry --> FeatureTools
|
|
685
|
-
GenerateText --> ToolRegistry
|
|
686
|
-
StreamText --> ToolRegistry
|
|
687
|
-
```
|
|
154
|
+
Provider failures use `IntelligenceProviderError`; invalid prompts and options
|
|
155
|
+
use `IntelligenceValidationError`; missing adapters or capability defaults use
|
|
156
|
+
`IntelligenceConfigurationError`.
|