@oh-my-pi/pi-agent-core 8.6.0 → 8.8.8
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/package.json +4 -4
- package/src/agent.ts +25 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-agent-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.8",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"test": "bun test"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@oh-my-pi/pi-ai": "8.
|
|
28
|
-
"@oh-my-pi/pi-tui": "8.
|
|
29
|
-
"@oh-my-pi/pi-utils": "8.
|
|
27
|
+
"@oh-my-pi/pi-ai": "8.8.8",
|
|
28
|
+
"@oh-my-pi/pi-tui": "8.8.8",
|
|
29
|
+
"@oh-my-pi/pi-utils": "8.8.8"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [
|
|
32
32
|
"ai",
|
package/src/agent.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
streamSimple,
|
|
14
14
|
type TextContent,
|
|
15
15
|
type ThinkingBudgets,
|
|
16
|
+
type ToolChoice,
|
|
16
17
|
type ToolResultMessage,
|
|
17
18
|
} from "@oh-my-pi/pi-ai";
|
|
18
19
|
import { agentLoop, agentLoopContinue } from "./agent-loop";
|
|
@@ -107,6 +108,10 @@ export interface AgentOptions {
|
|
|
107
108
|
cursorOnToolResult?: CursorToolResultHandler;
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
export interface AgentPromptOptions {
|
|
112
|
+
toolChoice?: ToolChoice;
|
|
113
|
+
}
|
|
114
|
+
|
|
110
115
|
/** Buffered Cursor tool result with text position at time of call */
|
|
111
116
|
interface CursorToolResultEntry {
|
|
112
117
|
toolResult: ToolResultMessage;
|
|
@@ -358,9 +363,13 @@ export class Agent {
|
|
|
358
363
|
}
|
|
359
364
|
|
|
360
365
|
/** Send a prompt with an AgentMessage */
|
|
361
|
-
async prompt(message: AgentMessage | AgentMessage[]): Promise<void>;
|
|
362
|
-
async prompt(input: string, images?: ImageContent[]): Promise<void>;
|
|
363
|
-
async prompt(
|
|
366
|
+
async prompt(message: AgentMessage | AgentMessage[], options?: AgentPromptOptions): Promise<void>;
|
|
367
|
+
async prompt(input: string, images?: ImageContent[], options?: AgentPromptOptions): Promise<void>;
|
|
368
|
+
async prompt(
|
|
369
|
+
input: string | AgentMessage | AgentMessage[],
|
|
370
|
+
imagesOrOptions?: ImageContent[] | AgentPromptOptions,
|
|
371
|
+
options?: AgentPromptOptions,
|
|
372
|
+
) {
|
|
364
373
|
if (this._state.isStreaming) {
|
|
365
374
|
throw new Error(
|
|
366
375
|
"Agent is already processing a prompt. Use steer() or followUp() to queue messages, or wait for completion.",
|
|
@@ -371,10 +380,19 @@ export class Agent {
|
|
|
371
380
|
if (!model) throw new Error("No model configured");
|
|
372
381
|
|
|
373
382
|
let msgs: AgentMessage[];
|
|
383
|
+
let promptOptions: AgentPromptOptions | undefined;
|
|
384
|
+
let images: ImageContent[] | undefined;
|
|
374
385
|
|
|
375
386
|
if (Array.isArray(input)) {
|
|
376
387
|
msgs = input;
|
|
388
|
+
promptOptions = imagesOrOptions as AgentPromptOptions | undefined;
|
|
377
389
|
} else if (typeof input === "string") {
|
|
390
|
+
if (Array.isArray(imagesOrOptions)) {
|
|
391
|
+
images = imagesOrOptions;
|
|
392
|
+
promptOptions = options;
|
|
393
|
+
} else {
|
|
394
|
+
promptOptions = imagesOrOptions;
|
|
395
|
+
}
|
|
378
396
|
const content: Array<TextContent | ImageContent> = [{ type: "text", text: input }];
|
|
379
397
|
if (images && images.length > 0) {
|
|
380
398
|
content.push(...images);
|
|
@@ -388,9 +406,10 @@ export class Agent {
|
|
|
388
406
|
];
|
|
389
407
|
} else {
|
|
390
408
|
msgs = [input];
|
|
409
|
+
promptOptions = imagesOrOptions as AgentPromptOptions | undefined;
|
|
391
410
|
}
|
|
392
411
|
|
|
393
|
-
await this._runLoop(msgs);
|
|
412
|
+
await this._runLoop(msgs, promptOptions);
|
|
394
413
|
}
|
|
395
414
|
|
|
396
415
|
/** Continue from current context (for retry after overflow) */
|
|
@@ -415,7 +434,7 @@ export class Agent {
|
|
|
415
434
|
* If messages are provided, starts a new conversation turn with those messages.
|
|
416
435
|
* Otherwise, continues from existing context.
|
|
417
436
|
*/
|
|
418
|
-
private async _runLoop(messages?: AgentMessage[]) {
|
|
437
|
+
private async _runLoop(messages?: AgentMessage[], options?: AgentPromptOptions) {
|
|
419
438
|
const model = this._state.model;
|
|
420
439
|
if (!model) throw new Error("No model configured");
|
|
421
440
|
|
|
@@ -467,6 +486,7 @@ export class Agent {
|
|
|
467
486
|
interruptMode: this.interruptMode,
|
|
468
487
|
sessionId: this._sessionId,
|
|
469
488
|
thinkingBudgets: this._thinkingBudgets,
|
|
489
|
+
toolChoice: options?.toolChoice,
|
|
470
490
|
convertToLlm: this.convertToLlm,
|
|
471
491
|
transformContext: this.transformContext,
|
|
472
492
|
getApiKey: this.getApiKey,
|