@rowan-agent/agent 0.26.0 → 0.28.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/dist/index.d.ts +6 -12
- package/dist/index.js +87 -62
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,24 +11,18 @@ type ModelInvokeOutput = {
|
|
|
11
11
|
model?: ModelRef;
|
|
12
12
|
usage?: LlmTokenUsage;
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
currentPhase: string;
|
|
19
|
-
availablePhases: string[];
|
|
20
|
-
turnNumber: number;
|
|
21
|
-
payload?: unknown;
|
|
14
|
+
type InternalModelLoopOptions = {
|
|
15
|
+
prompt: string;
|
|
16
|
+
tools?: readonly string[];
|
|
17
|
+
maxToolRounds?: number;
|
|
22
18
|
};
|
|
23
19
|
/** Execution capabilities for a phase — operates on PhaseContext. */
|
|
24
20
|
type PhaseExecution = {
|
|
25
|
-
snapshot(): PhaseContextSnapshot;
|
|
26
|
-
restore(snapshot: PhaseContextSnapshot): void;
|
|
27
21
|
invokeModel(context: PhaseContext, options?: {
|
|
28
22
|
output?: "reply" | "internal";
|
|
29
23
|
}): Promise<ModelInvokeOutput>;
|
|
24
|
+
runInternalModelLoop(context: PhaseContext, options: InternalModelLoopOptions): Promise<ModelInvokeOutput>;
|
|
30
25
|
reportStatus(status: PhaseStatus): Promise<void>;
|
|
31
|
-
executeTool(context: AgentContext, toolCall: ToolCall): Promise<ToolResult>;
|
|
32
26
|
executeTools(context: AgentContext, toolCalls: readonly ToolCall[], contentBlocks?: readonly ContentBlock[], meta?: {
|
|
33
27
|
model?: ModelRef;
|
|
34
28
|
usage?: LlmTokenUsage;
|
|
@@ -3402,4 +3396,4 @@ declare function parseFrontmatter<T = Record<string, unknown>>(raw: string): Fro
|
|
|
3402
3396
|
|
|
3403
3397
|
declare function createCoreTools(input?: CoreToolContext): Tool$1[];
|
|
3404
3398
|
|
|
3405
|
-
export { type AfterToolCall, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EntryPhaseSpec, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionCapability, type ExtensionCapabilityContribution, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, type ExtensionHost, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type ExtensionStateStore, type ExtensionToolContribution, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, type HostApiExtension, InMemoryConfigProvider, InMemoryExtensionHost, InMemoryStore, type InteractionRecord, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LiveInteractionEvent, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type ModelRetry, type OpaqueId, type Outcome$1 as Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInput, type PhaseInvocation, type PhaseMessageManager, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEndEvent, type RunEvent, type RunFailure, type RunId, type RunInteraction, RunInteractionBoundary, RunInteractionCancelledError, type RunInteractionDriver, type RunInteractionKind, type RunInteractionRequest, type RunInteractionState, type RunInteractionStatus, type RunListCursor, type RunRecord, type RunSnapshot, type RunStartEvent, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type SettingsBadge, type SettingsControl, type SettingsDefinition, type SettingsItem, type SettingsOption, type SettingsSection, type Skill, type SkillRegistration, SqliteStore, type TextContent, type ThinkingContent, type ThinkingDelta, type Tool$1 as Tool, type ToolCallContext, type ToolCallDelta, type ToolCallId, type ToolCallPresentationInput, type ToolCallPresentationOutput, type ToolCallSnapshot, type ToolCallState, type ToolContribution, type ToolDefinition, type ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, type WithdrawnUserInput, brandConfigToken, createCompactPhase, createCorePhases, createCoreTools, createDefaultPhase, createStopPhase, extensionSourceId, isConfigurationSnapshot, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhases, loadSkill, loadSkills, mergeToolCall, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };
|
|
3399
|
+
export { type AfterToolCall, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EntryPhaseSpec, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionCapability, type ExtensionCapabilityContribution, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, type ExtensionHost, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type ExtensionStateStore, type ExtensionToolContribution, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, type HostApiExtension, InMemoryConfigProvider, InMemoryExtensionHost, InMemoryStore, type InteractionRecord, type InternalModelLoopOptions, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LiveInteractionEvent, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type ModelInvokeOutput, type ModelRetry, type OpaqueId, type Outcome$1 as Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInput, type PhaseInvocation, type PhaseMessageManager, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEndEvent, type RunEvent, type RunFailure, type RunId, type RunInteraction, RunInteractionBoundary, RunInteractionCancelledError, type RunInteractionDriver, type RunInteractionKind, type RunInteractionRequest, type RunInteractionState, type RunInteractionStatus, type RunListCursor, type RunRecord, type RunSnapshot, type RunStartEvent, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type SettingsBadge, type SettingsControl, type SettingsDefinition, type SettingsItem, type SettingsOption, type SettingsSection, type Skill, type SkillRegistration, SqliteStore, type TextContent, type ThinkingContent, type ThinkingDelta, type Tool$1 as Tool, type ToolCallContext, type ToolCallDelta, type ToolCallId, type ToolCallPresentationInput, type ToolCallPresentationOutput, type ToolCallSnapshot, type ToolCallState, type ToolContribution, type ToolDefinition, type ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, type WithdrawnUserInput, brandConfigToken, createCompactPhase, createCorePhases, createCoreTools, createDefaultPhase, createStopPhase, extensionSourceId, isConfigurationSnapshot, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhases, loadSkill, loadSkills, mergeToolCall, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };
|
package/dist/index.js
CHANGED
|
@@ -2479,6 +2479,84 @@ function createStopPhase() {
|
|
|
2479
2479
|
disableImplicitInvocation: false
|
|
2480
2480
|
};
|
|
2481
2481
|
}
|
|
2482
|
+
async function runInternalModelLoop(context, execution, phase, options) {
|
|
2483
|
+
const working = { ...context, messages: [...context.messages] };
|
|
2484
|
+
working.messages.push(createMessage("user", options.prompt, {
|
|
2485
|
+
kind: "phase_input",
|
|
2486
|
+
phase
|
|
2487
|
+
}));
|
|
2488
|
+
let result = await execution.invokeModel(working, { output: "internal" });
|
|
2489
|
+
const maxRounds = options.maxToolRounds ?? 8;
|
|
2490
|
+
const isAllowedTool = (name) => {
|
|
2491
|
+
if (name === PhaseRouteTool) return false;
|
|
2492
|
+
if (options.tools) {
|
|
2493
|
+
return options.tools.includes(name);
|
|
2494
|
+
}
|
|
2495
|
+
return context.tools.some((tool) => tool.name === name);
|
|
2496
|
+
};
|
|
2497
|
+
for (let attempt = 0; attempt < maxRounds && result.toolCalls.length > 0; attempt += 1) {
|
|
2498
|
+
if (!result.toolCalls.some((call) => isAllowedTool(call.name))) break;
|
|
2499
|
+
const normalizedCalls = result.toolCalls.map((call) => ({
|
|
2500
|
+
...call,
|
|
2501
|
+
args: typeof call.args === "string" ? (() => {
|
|
2502
|
+
try {
|
|
2503
|
+
return JSON.parse(call.args);
|
|
2504
|
+
} catch {
|
|
2505
|
+
return call.args;
|
|
2506
|
+
}
|
|
2507
|
+
})() : call.args
|
|
2508
|
+
}));
|
|
2509
|
+
const toolUseParts = normalizedCalls.map((call) => ({
|
|
2510
|
+
type: "tool_use",
|
|
2511
|
+
id: call.id,
|
|
2512
|
+
name: call.name,
|
|
2513
|
+
input: call.args
|
|
2514
|
+
}));
|
|
2515
|
+
const assistantContent = result.contentBlocks.length > 0 ? contentBlocksToMessageContent(result.contentBlocks) : result.text ? [{ type: "text", text: result.text }, ...toolUseParts] : toolUseParts;
|
|
2516
|
+
working.messages.push(createMessage("assistant", assistantContent, {
|
|
2517
|
+
kind: "phase_tool",
|
|
2518
|
+
phase
|
|
2519
|
+
}));
|
|
2520
|
+
const allowedCalls = normalizedCalls.filter((call) => isAllowedTool(call.name));
|
|
2521
|
+
const executedResults = allowedCalls.length > 0 ? await execution.executeTools(
|
|
2522
|
+
working,
|
|
2523
|
+
allowedCalls,
|
|
2524
|
+
result.contentBlocks,
|
|
2525
|
+
result.model ? { model: result.model, usage: result.usage } : void 0
|
|
2526
|
+
) : [];
|
|
2527
|
+
const executedByCallId = new Map(executedResults.map((r) => [r.toolCallId, r]));
|
|
2528
|
+
const createErrorResult = (call) => {
|
|
2529
|
+
const message = `Tool ${call.name} is not available in Phase ${phase}`;
|
|
2530
|
+
return {
|
|
2531
|
+
toolCallId: call.id,
|
|
2532
|
+
toolName: call.name,
|
|
2533
|
+
ok: false,
|
|
2534
|
+
error: message,
|
|
2535
|
+
content: message
|
|
2536
|
+
};
|
|
2537
|
+
};
|
|
2538
|
+
const toolResults = normalizedCalls.map((call) => {
|
|
2539
|
+
if (isAllowedTool(call.name)) {
|
|
2540
|
+
const executed = executedByCallId.get(call.id);
|
|
2541
|
+
if (executed) return executed;
|
|
2542
|
+
}
|
|
2543
|
+
return createErrorResult(call);
|
|
2544
|
+
});
|
|
2545
|
+
for (const toolResult2 of toolResults) {
|
|
2546
|
+
working.messages.push(createMessage("tool", [{
|
|
2547
|
+
type: "tool_result",
|
|
2548
|
+
toolUseId: toolResult2.toolCallId,
|
|
2549
|
+
content: JSON.stringify(toolResult2),
|
|
2550
|
+
isError: !toolResult2.ok
|
|
2551
|
+
}], {
|
|
2552
|
+
kind: "phase_tool",
|
|
2553
|
+
phase
|
|
2554
|
+
}));
|
|
2555
|
+
}
|
|
2556
|
+
result = await execution.invokeModel(working, { output: "internal" });
|
|
2557
|
+
}
|
|
2558
|
+
return result;
|
|
2559
|
+
}
|
|
2482
2560
|
function createCompactPhase() {
|
|
2483
2561
|
return {
|
|
2484
2562
|
name: COMPACT_PHASE_ID,
|
|
@@ -2496,51 +2574,11 @@ function createCompactPhase() {
|
|
|
2496
2574
|
kind: "compacting",
|
|
2497
2575
|
message: "Compacting conversation context."
|
|
2498
2576
|
});
|
|
2499
|
-
const tools = context.tools.filter((tool) => tool.name === "read" || tool.name === "bash");
|
|
2500
|
-
const working = { ...context, tools, skills: [...context.skills], messages: [...context.messages] };
|
|
2501
2577
|
const instructions = compactInstructions(context);
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
})
|
|
2506
|
-
let result = await execution.invokeModel(working, { output: "internal" });
|
|
2507
|
-
for (let attempt = 0; attempt < 8 && result.toolCalls.length > 0; attempt += 1) {
|
|
2508
|
-
const calls = result.toolCalls.filter((call) => tools.some((tool) => tool.name === call.name));
|
|
2509
|
-
if (calls.length === 0) break;
|
|
2510
|
-
const normalizedCalls = calls.map((call) => ({
|
|
2511
|
-
...call,
|
|
2512
|
-
args: typeof call.args === "string" ? (() => {
|
|
2513
|
-
try {
|
|
2514
|
-
return JSON.parse(call.args);
|
|
2515
|
-
} catch {
|
|
2516
|
-
return call.args;
|
|
2517
|
-
}
|
|
2518
|
-
})() : call.args
|
|
2519
|
-
}));
|
|
2520
|
-
const assistantContent = result.contentBlocks.length > 0 ? contentBlocksToMessageContent(result.contentBlocks) : normalizedCalls.map((call) => ({ type: "tool_use", id: call.id, name: call.name, input: call.args }));
|
|
2521
|
-
working.messages.push(createMessage("assistant", assistantContent, {
|
|
2522
|
-
kind: "phase_tool",
|
|
2523
|
-
phase: COMPACT_PHASE_ID
|
|
2524
|
-
}));
|
|
2525
|
-
const toolResults = await execution.executeTools(
|
|
2526
|
-
working,
|
|
2527
|
-
normalizedCalls,
|
|
2528
|
-
result.contentBlocks,
|
|
2529
|
-
result.model ? { model: result.model, usage: result.usage } : void 0
|
|
2530
|
-
);
|
|
2531
|
-
for (const toolResult2 of toolResults) {
|
|
2532
|
-
working.messages.push(createMessage("tool", [{
|
|
2533
|
-
type: "tool_result",
|
|
2534
|
-
toolUseId: toolResult2.toolCallId,
|
|
2535
|
-
content: JSON.stringify(toolResult2),
|
|
2536
|
-
isError: !toolResult2.ok
|
|
2537
|
-
}], {
|
|
2538
|
-
kind: "phase_tool",
|
|
2539
|
-
phase: COMPACT_PHASE_ID
|
|
2540
|
-
}));
|
|
2541
|
-
}
|
|
2542
|
-
result = await execution.invokeModel(working, { output: "internal" });
|
|
2543
|
-
}
|
|
2578
|
+
const result = await execution.runInternalModelLoop(context, {
|
|
2579
|
+
prompt: buildCompactionPrompt(instructions),
|
|
2580
|
+
tools: ["read", "bash"]
|
|
2581
|
+
});
|
|
2544
2582
|
return {
|
|
2545
2583
|
route: "stop",
|
|
2546
2584
|
phase: COMPACT_PHASE_ID,
|
|
@@ -3738,25 +3776,9 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
|
|
|
3738
3776
|
return result;
|
|
3739
3777
|
});
|
|
3740
3778
|
};
|
|
3741
|
-
|
|
3779
|
+
const execution = {
|
|
3742
3780
|
interaction,
|
|
3743
3781
|
messages: messageManager,
|
|
3744
|
-
snapshot() {
|
|
3745
|
-
return {
|
|
3746
|
-
systemPrompt: config.context.systemPrompt,
|
|
3747
|
-
messages: [...config.context.messages],
|
|
3748
|
-
currentPhase: state.currentPhase ?? "",
|
|
3749
|
-
availablePhases: Array.from(registry.phases.keys()),
|
|
3750
|
-
turnNumber: state.metrics.iterations
|
|
3751
|
-
};
|
|
3752
|
-
},
|
|
3753
|
-
restore(snapshot) {
|
|
3754
|
-
config.context.systemPrompt = snapshot.systemPrompt;
|
|
3755
|
-
config.context.messages.length = 0;
|
|
3756
|
-
config.context.messages.push(...snapshot.messages);
|
|
3757
|
-
state.currentPhase = snapshot.currentPhase;
|
|
3758
|
-
state.metrics.iterations = snapshot.turnNumber;
|
|
3759
|
-
},
|
|
3760
3782
|
async invokeModel(phaseContext, options = {}) {
|
|
3761
3783
|
if (config.beforePrompt) {
|
|
3762
3784
|
phaseContext = await config.beforePrompt(phase.name, phaseContext);
|
|
@@ -3852,10 +3874,12 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
|
|
|
3852
3874
|
await config.onModelTranscript?.(result.transcript, { phase: phase.name, model: phase.model ?? config.model });
|
|
3853
3875
|
return result;
|
|
3854
3876
|
},
|
|
3877
|
+
async runInternalModelLoop(phaseContext, options) {
|
|
3878
|
+
return runInternalModelLoop(phaseContext, execution, phase.name, options);
|
|
3879
|
+
},
|
|
3855
3880
|
async reportStatus(status) {
|
|
3856
3881
|
await config.onPhaseStatus?.(phase.name, status);
|
|
3857
3882
|
},
|
|
3858
|
-
executeTool: executePhaseTool,
|
|
3859
3883
|
async executeTools(phaseContext, toolCalls, contentBlocks, meta) {
|
|
3860
3884
|
return runTurn(async () => {
|
|
3861
3885
|
const tools = phaseContext.tools.filter((tool) => tool.name !== PhaseRouteTool);
|
|
@@ -3885,6 +3909,7 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
|
|
|
3885
3909
|
});
|
|
3886
3910
|
}
|
|
3887
3911
|
};
|
|
3912
|
+
return execution;
|
|
3888
3913
|
}
|
|
3889
3914
|
function parallelPhaseReply(produced) {
|
|
3890
3915
|
const last = [...produced].reverse().find((message) => message.role === "assistant");
|