psadk 1.3.7 → 1.4.1
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 +52 -0
- package/README.md +150 -0
- package/build/main/lib/PSAI.d.ts +6 -0
- package/build/main/lib/PSAI.js +147 -79
- package/build/main/lib/PSAgent.js +77 -60
- package/build/main/lib/PSAgentConfig.d.ts +3 -0
- package/build/main/lib/PSAgentLogger.js +12 -9
- package/build/main/lib/PSAgentTask.js +4 -1
- package/build/main/lib/PSAgentTool.js +12 -2
- package/build/main/lib/agent-core/agent-loop.d.ts +23 -0
- package/build/main/lib/agent-core/agent-loop.js +479 -0
- package/build/main/lib/agent-core/agent.d.ts +124 -0
- package/build/main/lib/agent-core/agent.js +402 -0
- package/build/main/lib/agent-core/harness/agent-harness.d.ts +84 -0
- package/build/main/lib/agent-core/harness/agent-harness.js +728 -0
- package/build/main/lib/agent-core/harness/compaction/branch-summarization.d.ts +87 -0
- package/build/main/lib/agent-core/harness/compaction/branch-summarization.js +243 -0
- package/build/main/lib/agent-core/harness/compaction/compaction.d.ts +121 -0
- package/build/main/lib/agent-core/harness/compaction/compaction.js +616 -0
- package/build/main/lib/agent-core/harness/compaction/utils.d.ts +37 -0
- package/build/main/lib/agent-core/harness/compaction/utils.js +153 -0
- package/build/main/lib/agent-core/harness/env/nodejs.d.ts +43 -0
- package/build/main/lib/agent-core/harness/env/nodejs.js +348 -0
- package/build/main/lib/agent-core/harness/execution-env.d.ts +3 -0
- package/build/main/lib/agent-core/harness/execution-env.js +3 -0
- package/build/main/lib/agent-core/harness/messages.d.ts +50 -0
- package/build/main/lib/agent-core/harness/messages.js +102 -0
- package/build/main/lib/agent-core/harness/prompt-templates.d.ts +44 -0
- package/build/main/lib/agent-core/harness/prompt-templates.js +200 -0
- package/build/main/lib/agent-core/harness/session/repo/jsonl.d.ts +19 -0
- package/build/main/lib/agent-core/harness/session/repo/jsonl.js +92 -0
- package/build/main/lib/agent-core/harness/session/repo/memory.d.ts +17 -0
- package/build/main/lib/agent-core/harness/session/repo/memory.js +42 -0
- package/build/main/lib/agent-core/harness/session/repo/shared.d.ts +9 -0
- package/build/main/lib/agent-core/harness/session/repo/shared.js +31 -0
- package/build/main/lib/agent-core/harness/session/session.d.ts +31 -0
- package/build/main/lib/agent-core/harness/session/session.js +196 -0
- package/build/main/lib/agent-core/harness/session/storage/jsonl.d.ts +29 -0
- package/build/main/lib/agent-core/harness/session/storage/jsonl.js +170 -0
- package/build/main/lib/agent-core/harness/session/storage/memory.d.ts +25 -0
- package/build/main/lib/agent-core/harness/session/storage/memory.js +90 -0
- package/build/main/lib/agent-core/harness/skills.d.ts +40 -0
- package/build/main/lib/agent-core/harness/skills.js +259 -0
- package/build/main/lib/agent-core/harness/system-prompt.d.ts +2 -0
- package/build/main/lib/agent-core/harness/system-prompt.js +30 -0
- package/build/main/lib/agent-core/harness/types.d.ts +524 -0
- package/build/main/lib/agent-core/harness/types.js +16 -0
- package/build/main/lib/agent-core/harness/utils/shell-output.d.ts +13 -0
- package/build/main/lib/agent-core/harness/utils/shell-output.js +97 -0
- package/build/main/lib/agent-core/harness/utils/truncate.d.ts +69 -0
- package/build/main/lib/agent-core/harness/utils/truncate.js +205 -0
- package/build/main/lib/agent-core/index.d.ts +19 -0
- package/build/main/lib/agent-core/index.js +25 -0
- package/build/main/lib/agent-core/package.json +3 -0
- package/build/main/lib/agent-core/proxy.d.ts +68 -0
- package/build/main/lib/agent-core/proxy.js +278 -0
- package/build/main/lib/agent-core/types.d.ts +385 -0
- package/build/main/lib/agent-core/types.js +2 -0
- package/build/main/lib/skills/constants.js +6 -4
- package/build/main/lib/skills/skillParser.js +2 -2
- package/build/main/lib/skills/utils.js +8 -10
- package/build/main/lib/tools/BraveWebSearchTool.js +4 -3
- package/build/main/lib/tools/PSArtifactTool.js +3 -3
- package/build/main/lib/tools/PSClarifyTool.js +3 -2
- package/build/main/lib/tools/PSCommandLineTool.js +8 -7
- package/build/main/lib/tools/PSMemoryTool.js +9 -7
- package/build/main/lib/tools/PSReadFileTool.js +3 -3
- package/build/main/lib/tools/PSSkillTool.js +6 -4
- package/build/main/lib/tools/PSSubAgentTool.js +4 -5
- package/build/main/lib/tools/PSWriteFileTool.js +3 -3
- package/build/main/lib/tools/TodoTool.js +8 -4
- package/build/main/lib/utils/helpers.js +2 -13
- package/build/module/lib/PSAI.d.ts +6 -0
- package/build/module/lib/PSAI.js +112 -85
- package/build/module/lib/PSAgentConfig.d.ts +3 -0
- package/build/module/lib/agent-core/agent-loop.d.ts +23 -0
- package/build/module/lib/agent-core/agent-loop.js +479 -0
- package/build/module/lib/agent-core/agent.d.ts +124 -0
- package/build/module/lib/agent-core/agent.js +402 -0
- package/build/module/lib/agent-core/harness/agent-harness.d.ts +84 -0
- package/build/module/lib/agent-core/harness/agent-harness.js +728 -0
- package/build/module/lib/agent-core/harness/compaction/branch-summarization.d.ts +87 -0
- package/build/module/lib/agent-core/harness/compaction/branch-summarization.js +243 -0
- package/build/module/lib/agent-core/harness/compaction/compaction.d.ts +121 -0
- package/build/module/lib/agent-core/harness/compaction/compaction.js +616 -0
- package/build/module/lib/agent-core/harness/compaction/utils.d.ts +37 -0
- package/build/module/lib/agent-core/harness/compaction/utils.js +153 -0
- package/build/module/lib/agent-core/harness/env/nodejs.d.ts +43 -0
- package/build/module/lib/agent-core/harness/env/nodejs.js +348 -0
- package/build/module/lib/agent-core/harness/execution-env.d.ts +3 -0
- package/build/module/lib/agent-core/harness/execution-env.js +3 -0
- package/build/module/lib/agent-core/harness/messages.d.ts +50 -0
- package/build/module/lib/agent-core/harness/messages.js +102 -0
- package/build/module/lib/agent-core/harness/prompt-templates.d.ts +44 -0
- package/build/module/lib/agent-core/harness/prompt-templates.js +200 -0
- package/build/module/lib/agent-core/harness/session/repo/jsonl.d.ts +19 -0
- package/build/module/lib/agent-core/harness/session/repo/jsonl.js +92 -0
- package/build/module/lib/agent-core/harness/session/repo/memory.d.ts +17 -0
- package/build/module/lib/agent-core/harness/session/repo/memory.js +42 -0
- package/build/module/lib/agent-core/harness/session/repo/shared.d.ts +9 -0
- package/build/module/lib/agent-core/harness/session/repo/shared.js +31 -0
- package/build/module/lib/agent-core/harness/session/session.d.ts +31 -0
- package/build/module/lib/agent-core/harness/session/session.js +196 -0
- package/build/module/lib/agent-core/harness/session/storage/jsonl.d.ts +29 -0
- package/build/module/lib/agent-core/harness/session/storage/jsonl.js +170 -0
- package/build/module/lib/agent-core/harness/session/storage/memory.d.ts +25 -0
- package/build/module/lib/agent-core/harness/session/storage/memory.js +90 -0
- package/build/module/lib/agent-core/harness/skills.d.ts +40 -0
- package/build/module/lib/agent-core/harness/skills.js +259 -0
- package/build/module/lib/agent-core/harness/system-prompt.d.ts +2 -0
- package/build/module/lib/agent-core/harness/system-prompt.js +30 -0
- package/build/module/lib/agent-core/harness/types.d.ts +524 -0
- package/build/module/lib/agent-core/harness/types.js +16 -0
- package/build/module/lib/agent-core/harness/utils/shell-output.d.ts +13 -0
- package/build/module/lib/agent-core/harness/utils/shell-output.js +97 -0
- package/build/module/lib/agent-core/harness/utils/truncate.d.ts +69 -0
- package/build/module/lib/agent-core/harness/utils/truncate.js +205 -0
- package/build/module/lib/agent-core/index.d.ts +19 -0
- package/build/module/lib/agent-core/index.js +25 -0
- package/build/module/lib/agent-core/proxy.d.ts +68 -0
- package/build/module/lib/agent-core/proxy.js +278 -0
- package/build/module/lib/agent-core/types.d.ts +385 -0
- package/build/module/lib/agent-core/types.js +2 -0
- package/build/module/lib/tools/PSSkillTool.js +1 -1
- package/package.json +20 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.0 (2026-05-18)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **Prompt Caching Support**: Reduce costs and latency by up to 90% with built-in prompt caching
|
|
8
|
+
- New `enable_prompt_caching` parameter in `llm_config` for both PSAI and PSAgent ([#prompt-caching](https://pscode.lioncloud.net///commit/prompt-caching))
|
|
9
|
+
- New `cache_system_prompt` parameter to control system message caching
|
|
10
|
+
- New `cache_breakpoints` parameter for advanced cache control in agents
|
|
11
|
+
- Works with all LLM providers (OpenAI, Anthropic, Google Gemini, AWS Bedrock, Azure OpenAI)
|
|
12
|
+
- Automatic cache management through the LLM Gateway
|
|
13
|
+
- See `docs/PROMPT_CACHING.md` for comprehensive guide and examples
|
|
14
|
+
- Updated `PSAI.llm()` and `PSAI.llmStream()` to support prompt caching parameters
|
|
15
|
+
- Enhanced `PSAgentConfig` interface with caching configuration options
|
|
16
|
+
- Improved message formatting to support Anthropic-style cache_control blocks
|
|
17
|
+
|
|
18
|
+
### Documentation
|
|
19
|
+
|
|
20
|
+
- Add comprehensive prompt caching guide ([docs/PROMPT_CACHING.md](docs/PROMPT_CACHING.md))
|
|
21
|
+
- Add prompt caching examples ([examples/prompt-caching-example.ts](examples/prompt-caching-example.ts))
|
|
22
|
+
- Update README with feature highlights and caching documentation link
|
|
23
|
+
|
|
24
|
+
### Non-Breaking Changes
|
|
25
|
+
|
|
26
|
+
- All caching features are opt-in via configuration
|
|
27
|
+
- Existing code continues to work without modification
|
|
28
|
+
- Default behavior unchanged (caching disabled by default)
|
|
29
|
+
|
|
30
|
+
## 1.3.8 (2026-05-15)
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
- **agent-core**: Add new agent-core module for low-level agent runtime
|
|
35
|
+
- Stateful agent wrapper with lifecycle management
|
|
36
|
+
- Event-driven execution loop with tool calling
|
|
37
|
+
- LLM proxy for server-side routing
|
|
38
|
+
- Built on @mariozechner/pi-ai library
|
|
39
|
+
- Import via `psadk/agent-core` subpath export
|
|
40
|
+
- **appToken**: Add support for app-level authentication tokens
|
|
41
|
+
- All API methods now support optional `X-App-Authorization` header
|
|
42
|
+
- Pass `appToken` parameter to PSAI constructor
|
|
43
|
+
|
|
44
|
+
### Dependencies
|
|
45
|
+
|
|
46
|
+
- Add @mariozechner/pi-ai (^0.73.0)
|
|
47
|
+
- Add typebox (^1.1.38) for runtime type validation
|
|
48
|
+
- Add undici-types dev dependency
|
|
49
|
+
|
|
50
|
+
### Build
|
|
51
|
+
|
|
52
|
+
- Update TypeScript configuration to support DOM types for HeadersInit
|
|
53
|
+
- Add skipLibCheck to resolve dependency type issues
|
|
54
|
+
|
|
3
55
|
## 1.1.0 (2025-09-17)
|
|
4
56
|
|
|
5
57
|
### Features
|
package/README.md
CHANGED
|
@@ -10,10 +10,160 @@ ps adk adapter
|
|
|
10
10
|
$ npm install psadk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Multi-Provider LLM Support**: OpenAI, Anthropic, Google Gemini, AWS Bedrock, Azure OpenAI, and more
|
|
16
|
+
- **A2A Protocol Compatible**: Build agents that work with the Agent-to-Agent protocol
|
|
17
|
+
- **Prompt Caching**: Reduce costs and latency with built-in prompt caching support (90% cost reduction!)
|
|
18
|
+
- **Custom Tools**: Create and integrate custom tools with your agents
|
|
19
|
+
- **Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
20
|
+
- **Authentication**: Built-in JWT authentication and token management
|
|
21
|
+
|
|
13
22
|
## Documentation
|
|
14
23
|
|
|
15
24
|
The classes are documented here [Documentation](./globals.md)
|
|
16
25
|
|
|
26
|
+
**New:** [Prompt Caching Guide](./docs/PROMPT_CACHING.md) - Learn how to reduce costs and latency by 90% with prompt caching
|
|
27
|
+
|
|
28
|
+
## Agent Core Module
|
|
29
|
+
|
|
30
|
+
The `agent-core` module provides a low-level, event-driven agent runtime built on `@earendil-works/pi-ai`. This module is designed for advanced use cases where you need fine-grained control over agent execution, tool calling, and message handling.
|
|
31
|
+
|
|
32
|
+
> **Note**: The `agent-core` module adds additional dependencies including LLM provider SDKs. It's imported separately via `psadk/agent-core` to keep the main package lightweight.
|
|
33
|
+
|
|
34
|
+
### Installation
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Agent } from 'psadk/agent-core';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Key Features
|
|
41
|
+
|
|
42
|
+
- **Stateful Agent Execution**: Lifecycle management with states (idle, running, stopped, error)
|
|
43
|
+
- **Event-Driven Architecture**: Hooks for messages, thinking, tool calls, and errors
|
|
44
|
+
- **Tool Execution**: Sequential and parallel tool calling modes
|
|
45
|
+
- **Message History**: Automatic tracking and state management
|
|
46
|
+
- **LLM Proxy**: Server-side routing for LLM calls
|
|
47
|
+
- **Type Safety**: Comprehensive TypeScript types with runtime validation using TypeBox
|
|
48
|
+
|
|
49
|
+
### Basic Example
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Agent } from 'psadk/agent-core';
|
|
53
|
+
|
|
54
|
+
const agent = new Agent({
|
|
55
|
+
name: 'MyAgent',
|
|
56
|
+
model: 'gpt-4',
|
|
57
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
58
|
+
tools: [
|
|
59
|
+
{
|
|
60
|
+
name: 'get_weather',
|
|
61
|
+
description: 'Get the current weather for a location',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
location: { type: 'string' },
|
|
66
|
+
},
|
|
67
|
+
required: ['location'],
|
|
68
|
+
},
|
|
69
|
+
execute: async ({ location }) => {
|
|
70
|
+
// Implementation
|
|
71
|
+
return { temperature: 72, conditions: 'sunny' };
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
onMessage: (msg) => console.log('Agent:', msg.content),
|
|
76
|
+
onThinking: (thinking) => console.log('Thinking:', thinking),
|
|
77
|
+
onToolCall: (toolCall) => console.log('Tool:', toolCall.name),
|
|
78
|
+
onError: (error) => console.error('Error:', error),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Start the agent and send a message
|
|
82
|
+
await agent.run("What's the weather in San Francisco?");
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Agent Configuration
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
interface AgentConfig {
|
|
89
|
+
name: string;
|
|
90
|
+
model: string;
|
|
91
|
+
systemPrompt?: string;
|
|
92
|
+
tools?: Tool[];
|
|
93
|
+
parallel?: boolean; // Enable parallel tool execution
|
|
94
|
+
maxSteps?: number; // Maximum number of execution steps
|
|
95
|
+
onMessage?: (message: Message) => void;
|
|
96
|
+
onThinking?: (thinking: string) => void;
|
|
97
|
+
onToolCall?: (toolCall: ToolCall) => void;
|
|
98
|
+
onToolResult?: (result: ToolResult) => void;
|
|
99
|
+
onError?: (error: Error) => void;
|
|
100
|
+
onStateChange?: (state: AgentState) => void;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Advanced: Using the Proxy
|
|
105
|
+
|
|
106
|
+
The proxy module allows you to route LLM calls through a server:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { ProxyStream } from 'psadk/agent-core';
|
|
110
|
+
|
|
111
|
+
const proxy = new ProxyStream({
|
|
112
|
+
endpoint: 'https://your-server.com/llm',
|
|
113
|
+
apiKey: 'your-api-key',
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const stream = await proxy.createCompletion({
|
|
117
|
+
model: 'gpt-4',
|
|
118
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
for await (const chunk of stream) {
|
|
122
|
+
console.log(chunk);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Agent Lifecycle
|
|
127
|
+
|
|
128
|
+
The agent follows a state machine:
|
|
129
|
+
|
|
130
|
+
1. **idle**: Initial state, ready to accept tasks
|
|
131
|
+
2. **running**: Actively processing a task
|
|
132
|
+
3. **stopped**: Gracefully stopped
|
|
133
|
+
4. **error**: Encountered an error
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
agent.onStateChange((state) => {
|
|
137
|
+
console.log(`Agent state changed to: ${state}`);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Stop the agent
|
|
141
|
+
await agent.stop();
|
|
142
|
+
|
|
143
|
+
// Reset to idle state
|
|
144
|
+
await agent.reset();
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Error Handling
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const agent = new Agent({
|
|
151
|
+
name: 'SafeAgent',
|
|
152
|
+
model: 'gpt-4',
|
|
153
|
+
onError: (error) => {
|
|
154
|
+
console.error('Agent error:', error.message);
|
|
155
|
+
// Handle error (e.g., retry, alert, log)
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
await agent.run('Process this task');
|
|
161
|
+
} catch (error) {
|
|
162
|
+
// Errors are also thrown, so you can handle them here
|
|
163
|
+
console.error('Task failed:', error);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
17
167
|
## Developing with PSADK
|
|
18
168
|
|
|
19
169
|
### A2A Server
|
package/build/main/lib/PSAI.d.ts
CHANGED
|
@@ -11,12 +11,16 @@ export declare class PSAI {
|
|
|
11
11
|
embedQuery(text: string, embeddingModel?: string): Promise<number[]>;
|
|
12
12
|
embedDocuments(text: string[], embeddingModel?: string): Promise<number[][]>;
|
|
13
13
|
getModels(): Promise<any>;
|
|
14
|
+
private prepareMessages;
|
|
15
|
+
private buildRequest;
|
|
14
16
|
llm(prompt: string, model?: string, systemmsg?: string, llm_config?: {
|
|
15
17
|
presence_penalty?: number;
|
|
16
18
|
frequency_penalty?: number;
|
|
17
19
|
max_tokens?: number;
|
|
18
20
|
temperature?: number;
|
|
19
21
|
top_p?: number;
|
|
22
|
+
enable_prompt_caching?: boolean;
|
|
23
|
+
cache_system_prompt?: boolean;
|
|
20
24
|
} & Record<string, any>): Promise<any>;
|
|
21
25
|
llmStream(prompt: string, model?: string, systemmsg?: string, llm_config?: {
|
|
22
26
|
presence_penalty?: number;
|
|
@@ -24,6 +28,8 @@ export declare class PSAI {
|
|
|
24
28
|
max_tokens?: number;
|
|
25
29
|
temperature?: number;
|
|
26
30
|
top_p?: number;
|
|
31
|
+
enable_prompt_caching?: boolean;
|
|
32
|
+
cache_system_prompt?: boolean;
|
|
27
33
|
} & Record<string, any>): Promise<any>;
|
|
28
34
|
static getServiceToken(options?: Record<string, string>): Promise<string>;
|
|
29
35
|
/**
|