@oh-my-pi/pi-agent-core 3.32.0 → 3.34.0
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/README.md +2 -2
- package/package.json +3 -3
- package/src/agent-loop.ts +32 -3
- package/src/agent.ts +1 -8
- package/src/proxy.ts +2 -2
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @oh-my-pi/pi-agent
|
|
2
2
|
|
|
3
|
-
Stateful agent with tool execution and event streaming. Built on `@
|
|
3
|
+
Stateful agent with tool execution and event streaming. Built on `@oh-my-pi/pi-ai`.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ npm install @oh-my-pi/pi-agent
|
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { Agent } from "@oh-my-pi/pi-agent";
|
|
15
|
-
import { getModel } from "@
|
|
15
|
+
import { getModel } from "@oh-my-pi/pi-ai";
|
|
16
16
|
|
|
17
17
|
const agent = new Agent({
|
|
18
18
|
initialState: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-agent-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.34.0",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test": "vitest --run"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@oh-my-pi/pi-tui": "3.
|
|
16
|
+
"@oh-my-pi/pi-ai": "3.34.0",
|
|
17
|
+
"@oh-my-pi/pi-tui": "3.34.0"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"ai",
|
package/src/agent-loop.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
streamSimple,
|
|
11
11
|
type ToolResultMessage,
|
|
12
12
|
validateToolArguments,
|
|
13
|
-
} from "@
|
|
13
|
+
} from "@oh-my-pi/pi-ai";
|
|
14
14
|
import type {
|
|
15
15
|
AgentContext,
|
|
16
16
|
AgentEvent,
|
|
@@ -98,6 +98,32 @@ function createAgentStream(): EventStream<AgentEvent, AgentMessage[]> {
|
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
function normalizeMessagesForProvider(
|
|
102
|
+
messages: Context["messages"],
|
|
103
|
+
model: AgentLoopConfig["model"],
|
|
104
|
+
): Context["messages"] {
|
|
105
|
+
if (model.provider !== "cerebras") {
|
|
106
|
+
return messages;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let changed = false;
|
|
110
|
+
const normalized = messages.map((message) => {
|
|
111
|
+
if (message.role !== "assistant" || !Array.isArray(message.content)) {
|
|
112
|
+
return message;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const filtered = message.content.filter((block) => block.type !== "thinking");
|
|
116
|
+
if (filtered.length === message.content.length) {
|
|
117
|
+
return message;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
changed = true;
|
|
121
|
+
return { ...message, content: filtered };
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return changed ? normalized : messages;
|
|
125
|
+
}
|
|
126
|
+
|
|
101
127
|
/**
|
|
102
128
|
* Main loop logic shared by agentLoop and agentLoopContinue.
|
|
103
129
|
*/
|
|
@@ -218,11 +244,12 @@ async function streamAssistantResponse(
|
|
|
218
244
|
|
|
219
245
|
// Convert to LLM-compatible messages (AgentMessage[] → Message[])
|
|
220
246
|
const llmMessages = await config.convertToLlm(messages);
|
|
247
|
+
const normalizedMessages = normalizeMessagesForProvider(llmMessages, config.model);
|
|
221
248
|
|
|
222
249
|
// Build LLM context
|
|
223
250
|
const llmContext: Context = {
|
|
224
251
|
systemPrompt: context.systemPrompt,
|
|
225
|
-
messages:
|
|
252
|
+
messages: normalizedMessages,
|
|
226
253
|
tools: context.tools,
|
|
227
254
|
};
|
|
228
255
|
|
|
@@ -244,8 +271,9 @@ async function streamAssistantResponse(
|
|
|
244
271
|
for await (const event of response) {
|
|
245
272
|
// Check for abort signal before processing each event
|
|
246
273
|
if (signal?.aborted) {
|
|
274
|
+
const errorMessage = "Request was aborted";
|
|
247
275
|
const abortedMessage: AssistantMessage = partialMessage
|
|
248
|
-
? { ...partialMessage, stopReason: "aborted" }
|
|
276
|
+
? { ...partialMessage, stopReason: "aborted", errorMessage }
|
|
249
277
|
: {
|
|
250
278
|
role: "assistant",
|
|
251
279
|
content: [],
|
|
@@ -261,6 +289,7 @@ async function streamAssistantResponse(
|
|
|
261
289
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
262
290
|
},
|
|
263
291
|
stopReason: "aborted",
|
|
292
|
+
errorMessage,
|
|
264
293
|
timestamp: Date.now(),
|
|
265
294
|
};
|
|
266
295
|
if (addedPartial) {
|
package/src/agent.ts
CHANGED
|
@@ -3,14 +3,7 @@
|
|
|
3
3
|
* No transport abstraction - calls streamSimple via the loop.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
getModel,
|
|
8
|
-
type ImageContent,
|
|
9
|
-
type Message,
|
|
10
|
-
type Model,
|
|
11
|
-
streamSimple,
|
|
12
|
-
type TextContent,
|
|
13
|
-
} from "@mariozechner/pi-ai";
|
|
6
|
+
import { getModel, type ImageContent, type Message, type Model, streamSimple, type TextContent } from "@oh-my-pi/pi-ai";
|
|
14
7
|
import { agentLoop, agentLoopContinue } from "./agent-loop";
|
|
15
8
|
import type {
|
|
16
9
|
AgentContext,
|
package/src/proxy.ts
CHANGED
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
type SimpleStreamOptions,
|
|
13
13
|
type StopReason,
|
|
14
14
|
type ToolCall,
|
|
15
|
-
} from "@
|
|
16
|
-
import { parseStreamingJson } from "@
|
|
15
|
+
} from "@oh-my-pi/pi-ai";
|
|
16
|
+
import { parseStreamingJson } from "@oh-my-pi/pi-ai/src/utils/json-parse";
|
|
17
17
|
|
|
18
18
|
// Create stream class matching ProxyMessageEventStream
|
|
19
19
|
class ProxyMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
|
package/src/types.ts
CHANGED