Menu

Integrations Package (@astack-tech/integrations)

Relevant source files

The @astack-tech/integrations package provides external service integrations for the AStack framework, primarily focused on Large Language Model (LLM) provider implementations. This package abstracts vendor-specific APIs behind a unified ModelProvider interface, enabling agents and other components to interact with different LLM services without code changes.

For detailed documentation of the ModelProvider interface specification, see Model Provider Interface. For implementation details of the Deepseek provider, see Deepseek Integration. For information on how agents consume model providers, see Base Agent.

Sources: packages/integrations/package.json1-63 packages/integrations/src/model-provider/deepseek/index.ts1-522

Package Structure

The integrations package is organized as a single package with multiple export paths, following modern ESM/CJS dual-format conventions:

Export PathPurposeTypes Location
@astack-tech/integrationsMain package entry point./dist/index.d.ts
@astack-tech/integrations/model-providerModel provider implementations./dist/model-provider/index.d.ts

The package supports both ESM (import) and CommonJS (require) module systems through conditional exports defined in packages/integrations/package.json9-26

Package Dependencies

Sources: packages/integrations/package.json59-62

Model Provider Abstraction

The integrations package implements the ModelProvider interface defined in the components package. This interface standardizes how agents and other components interact with LLM services:

Sources: packages/components/src/agents/index.ts160-184 packages/integrations/src/model-provider/deepseek/index.ts125-174

Deepseek Integration

The Deepseek class is the primary model provider implementation, using the OpenAI SDK to communicate with Deepseek's OpenAI-compatible API endpoint.

Class Definition

The Deepseek component extends the base Component class and implements the ModelProvider interface:

Sources: packages/integrations/src/model-provider/deepseek/index.ts125-174

Core Methods

MethodSignaturePurpose
generateCompletion()async generateCompletion(prompt: string): Promise<string>Generate text completion from a simple prompt
chatCompletion()async chatCompletion(messages: Message[], options?): Promise<Message>Generate response from conversation messages
streamChatCompletion()async *streamChatCompletion(messages: Message[], options?): AsyncGenerator<Partial<Message>>Stream response chunks in real-time
run()async run(input: string | Message[]): Promise<string | Message>Standalone execution mode
_transform()_transform($i: any, $o: any): voidPipeline execution mode

Sources: packages/integrations/src/model-provider/deepseek/index.ts176-517

Configuration Interface

The DeepseekConfig interface defines all configuration options for initializing a Deepseek provider instance:

Configuration Fields

FieldTypeRequiredDefaultDescription
apiKeystringYes-Deepseek API authentication key
modelstringNo'deepseek-chat'Model identifier to use
baseURLstringNo'https://api.deepseek.com/v1'API endpoint URL
temperaturenumberNo0.7Controls output randomness (0-2)
maxTokensnumberNoundefinedMaximum tokens to generate
topPnumberNoundefinedNucleus sampling probability
systemPromptstringNoundefinedSystem-level instructions
rawToolsArray<Tool>NoundefinedTool instances (auto-converted to API format)
toolsunknown[]NoundefinedPre-formatted API tool definitions

Tool Configuration

Tools can be provided in two formats:

  1. Raw Tools Format (rawTools): Simple tool objects that are automatically converted to API format packages/integrations/src/model-provider/deepseek/index.ts154-163
  2. API Format (tools): Pre-formatted OpenAI-compatible tool definitions packages/integrations/src/model-provider/deepseek/index.ts164-167

Sources: packages/integrations/src/model-provider/deepseek/index.ts7-60 packages/integrations/src/model-provider/deepseek/index.ts137-167

Message and Tool Call Formats

Message Interface

The Message interface defines the structure for conversation messages:

Sources: packages/integrations/src/model-provider/deepseek/index.ts64-110

ToolCall Interface

The ToolCall interface represents a tool invocation request from the model:

The Deepseek implementation also handles OpenAI's standard format with nested function objects packages/integrations/src/model-provider/deepseek/index.ts448-467 ensuring compatibility with the Agent component's expectations.

Sources: packages/integrations/src/model-provider/deepseek/index.ts68-85

Execution Flow

Chat Completion Flow

Sources: packages/integrations/src/model-provider/deepseek/index.ts351-471

Streaming Flow

Sources: packages/integrations/src/model-provider/deepseek/index.ts233-343

Component Execution Modes

Standalone Mode

The Deepseek component can be executed directly via the run() method:

Sources: packages/integrations/src/model-provider/deepseek/index.ts478-484

Pipeline Mode

When used in a pipeline, the component's _transform() method handles port-based data flow:

Input PortData TypeHandler Method
'prompt'stringgenerateCompletion()
'messages'Message[]chatCompletion()
Output PortData TypeSource
'completion'stringFrom generateCompletion()
'message'MessageFrom chatCompletion()

Sources: packages/integrations/src/model-provider/deepseek/index.ts491-517

Usage Example

The following demonstrates how to instantiate and use the Deepseek provider:

Sources: examples/agent-with-tools/index.ts104-153

Tool Integration

The Deepseek provider supports tool calling through two mechanisms:

Configuration-Time Tools

Tools provided during construction via rawTools or tools are included in all API calls:

Sources: packages/integrations/src/model-provider/deepseek/index.ts154-167

Runtime Temporary Tools

Tools can be provided at call-time via the temporaryTools option, overriding configured tools:

Sources: packages/integrations/src/model-provider/deepseek/index.ts395-430

Error Handling

The component implements try-catch error handling in its _transform() method for pipeline execution:

Error LocationHandling Strategy
generateCompletion()Sends "API 调用错误" to output port
chatCompletion()Sends error message object with role: 'assistant'

Sources: packages/integrations/src/model-provider/deepseek/index.ts494-516

Package Metadata

PropertyValue
Package Name@astack-tech/integrations
Version0.1.1-beta.2
LicenseMIT
Node Version>=18.0.0
Build Tooltsup
Test Frameworkvitest

Sources: packages/integrations/package.json1-63