@inflexa-ai/harness 0.39.2 → 0.40.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 -3
- package/dist/agents/conversation-agent.d.ts +3 -0
- package/dist/agents/conversation-agent.js +13 -2
- package/dist/agents/report-session-agent.d.ts +3 -0
- package/dist/agents/report-session-agent.js +2 -0
- package/dist/agents/sandbox/cheminformatics-agent.js +0 -3
- package/dist/agents/sandbox/shared.d.ts +11 -2
- package/dist/agents/sandbox/shared.js +4 -0
- package/dist/app/chat-turn.d.ts +75 -12
- package/dist/app/chat-turn.js +149 -21
- package/dist/app/message-assembly.d.ts +16 -52
- package/dist/app/message-assembly.js +41 -68
- package/dist/app/run-activity.d.ts +4 -6
- package/dist/app/run-activity.js +7 -27
- package/dist/app/spawn-report-session.d.ts +6 -11
- package/dist/app/spawn-report-session.js +5 -6
- package/dist/app/synthesize-run.d.ts +3 -0
- package/dist/app/synthesize-run.js +1 -0
- package/dist/billing/usage-recorder.d.ts +3 -4
- package/dist/billing/usage-recorder.js +3 -4
- package/dist/contracts/chat-parts.d.ts +11 -1
- package/dist/contracts/chat-parts.js +1 -0
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/part-registry.js +1 -0
- package/dist/contracts/report-blocks.d.ts +8 -8
- package/dist/contracts/schemas/chat-parts.d.ts +32 -9
- package/dist/contracts/schemas/chat-parts.js +10 -0
- package/dist/execution/artifact-metadata.d.ts +26 -33
- package/dist/execution/artifact-metadata.js +44 -106
- package/dist/execution/post-step-pipeline.d.ts +23 -16
- package/dist/execution/post-step-pipeline.js +19 -21
- package/dist/execution/run-synthesis.d.ts +3 -0
- package/dist/execution/run-synthesis.js +11 -1
- package/dist/execution/step-summary.d.ts +21 -30
- package/dist/execution/step-summary.js +30 -57
- package/dist/index.d.ts +9 -8
- package/dist/index.js +15 -34
- package/dist/lib/zod-issues.js +2 -4
- package/dist/loop/compaction.d.ts +20 -0
- package/dist/loop/compaction.js +2 -0
- package/dist/loop/continue-agent.d.ts +40 -0
- package/dist/loop/continue-agent.js +38 -0
- package/dist/loop/metrics.d.ts +30 -22
- package/dist/loop/metrics.js +51 -22
- package/dist/loop/run-agent.d.ts +111 -13
- package/dist/loop/run-agent.js +467 -220
- package/dist/loop/run-to-terminal.d.ts +16 -17
- package/dist/loop/run-to-terminal.js +24 -35
- package/dist/loop/tool-mask.d.ts +23 -0
- package/dist/loop/tool-mask.js +46 -0
- package/dist/loop/tool-output.d.ts +48 -0
- package/dist/loop/tool-output.js +79 -0
- package/dist/loop/types.d.ts +6 -3
- package/dist/memory/ai-sdk-message-storage.d.ts +49 -2
- package/dist/memory/ai-sdk-message-storage.js +78 -2
- package/dist/memory/conversation-display-recorder.d.ts +6 -0
- package/dist/memory/conversation-display-recorder.js +64 -22
- package/dist/memory/conversation-display-replay.d.ts +5 -14
- package/dist/memory/conversation-display-replay.js +66 -32
- package/dist/memory/conversation-display-storage.d.ts +2 -1
- package/dist/memory/conversation-display-storage.js +2 -1
- package/dist/memory/conversation-view.d.ts +53 -0
- package/dist/memory/conversation-view.js +130 -0
- package/dist/memory/count-tokens.d.ts +5 -7
- package/dist/memory/count-tokens.js +7 -9
- package/dist/memory/thread-history.d.ts +74 -102
- package/dist/memory/thread-history.js +181 -246
- package/dist/memory/thread-store.d.ts +3 -3
- package/dist/memory/thread-store.js +7 -2
- package/dist/memory/tool-call-integrity.d.ts +15 -21
- package/dist/memory/tool-call-integrity.js +31 -38
- package/dist/memory/working-memory.d.ts +2 -5
- package/dist/memory/working-memory.js +2 -5
- package/dist/prompts/SOUL.d.ts +2 -2
- package/dist/prompts/SOUL.js +2 -7
- package/dist/prompts/analogical-reasoner.d.ts +1 -1
- package/dist/prompts/analogical-reasoner.js +16 -32
- package/dist/prompts/briefing.js +1 -1
- package/dist/prompts/compaction.d.ts +4 -0
- package/dist/prompts/compaction.js +24 -0
- package/dist/prompts/conversation.d.ts +1 -1
- package/dist/prompts/conversation.js +26 -35
- package/dist/prompts/execute-analysis/step-summary.js +7 -5
- package/dist/prompts/literature-reviewer.d.ts +1 -1
- package/dist/prompts/literature-reviewer.js +29 -34
- package/dist/prompts/planner.js +15 -29
- package/dist/prompts/report-session.d.ts +1 -1
- package/dist/prompts/report-session.js +2 -33
- package/dist/prompts/sandbox/bulk-transcriptomics-agent.d.ts +1 -1
- package/dist/prompts/sandbox/bulk-transcriptomics-agent.js +1 -2
- package/dist/prompts/sandbox/cheminformatics-agent.d.ts +1 -1
- package/dist/prompts/sandbox/cheminformatics-agent.js +10 -29
- package/dist/prompts/sandbox/chromatin-agent.d.ts +1 -1
- package/dist/prompts/sandbox/chromatin-agent.js +1 -2
- package/dist/prompts/sandbox/data-profiler.js +6 -3
- package/dist/prompts/sandbox/dna-methylation-agent.d.ts +1 -1
- package/dist/prompts/sandbox/dna-methylation-agent.js +2 -7
- package/dist/prompts/sandbox/drug-repurposing-agent.d.ts +1 -1
- package/dist/prompts/sandbox/drug-repurposing-agent.js +20 -24
- package/dist/prompts/sandbox/enrichment-agent.d.ts +1 -1
- package/dist/prompts/sandbox/enrichment-agent.js +3 -2
- package/dist/prompts/sandbox/genomic-variant-agent.d.ts +1 -1
- package/dist/prompts/sandbox/genomic-variant-agent.js +0 -2
- package/dist/prompts/sandbox/immune-profiling-agent.d.ts +1 -1
- package/dist/prompts/sandbox/immune-profiling-agent.js +7 -14
- package/dist/prompts/sandbox/metabolomics-agent.d.ts +1 -1
- package/dist/prompts/sandbox/metabolomics-agent.js +0 -2
- package/dist/prompts/sandbox/microbiome-agent.d.ts +1 -1
- package/dist/prompts/sandbox/microbiome-agent.js +14 -21
- package/dist/prompts/sandbox/multi-omics-integration-agent.d.ts +1 -1
- package/dist/prompts/sandbox/multi-omics-integration-agent.js +9 -19
- package/dist/prompts/sandbox/multimodal-sc-agent.d.ts +1 -1
- package/dist/prompts/sandbox/multimodal-sc-agent.js +4 -5
- package/dist/prompts/sandbox/network-agent.d.ts +1 -1
- package/dist/prompts/sandbox/network-agent.js +7 -8
- package/dist/prompts/sandbox/pkpd-clinical-response-agent.d.ts +1 -1
- package/dist/prompts/sandbox/pkpd-clinical-response-agent.js +19 -19
- package/dist/prompts/sandbox/proteomics-agent.d.ts +1 -1
- package/dist/prompts/sandbox/proteomics-agent.js +3 -4
- package/dist/prompts/sandbox/scientific-executor.d.ts +1 -1
- package/dist/prompts/sandbox/scientific-executor.js +7 -10
- package/dist/prompts/sandbox/single-cell-agent.d.ts +1 -1
- package/dist/prompts/sandbox/single-cell-agent.js +2 -4
- package/dist/prompts/sandbox/spatial-omics-agent.d.ts +1 -1
- package/dist/prompts/sandbox/spatial-omics-agent.js +3 -5
- package/dist/prompts/sandbox/statistical-modeling-agent.d.ts +1 -1
- package/dist/prompts/sandbox/statistical-modeling-agent.js +1 -1
- package/dist/prompts/sandbox/translational-safety-agent.d.ts +1 -1
- package/dist/prompts/sandbox/translational-safety-agent.js +10 -19
- package/dist/prompts/sandbox-standards.d.ts +7 -7
- package/dist/prompts/sandbox-standards.js +74 -76
- package/dist/prompts/synthesis-agent.d.ts +1 -1
- package/dist/prompts/synthesis-agent.js +16 -42
- package/dist/providers/ai-sdk.d.ts +39 -6
- package/dist/providers/ai-sdk.js +117 -18
- package/dist/providers/errors.d.ts +2 -0
- package/dist/providers/errors.js +5 -0
- package/dist/providers/prompt-cache.d.ts +43 -41
- package/dist/providers/prompt-cache.js +47 -41
- package/dist/providers/reasoning.d.ts +10 -21
- package/dist/providers/reasoning.js +10 -21
- package/dist/providers/types.d.ts +21 -5
- package/dist/report-model/authoring-grammar.d.ts +2 -2
- package/dist/runtime/assemble.d.ts +9 -7
- package/dist/runtime/assemble.js +7 -3
- package/dist/sandbox/create-sandbox.d.ts +2 -2
- package/dist/sandbox/submit-exec.d.ts +1 -1
- package/dist/schemas/artifact-manifest.d.ts +4 -4
- package/dist/state/init.js +39 -4
- package/dist/state/purge-analysis.js +4 -0
- package/dist/state/tool-outputs.d.ts +4 -0
- package/dist/state/tool-outputs.js +30 -0
- package/dist/tasks/data-profile.d.ts +3 -0
- package/dist/tasks/data-profile.js +2 -0
- package/dist/tools/ad-hoc-router.d.ts +8 -0
- package/dist/tools/ad-hoc-router.js +21 -2
- package/dist/tools/display/show-user.d.ts +1 -1
- package/dist/tools/execute-analysis.d.ts +3 -0
- package/dist/tools/execute-analysis.js +9 -1
- package/dist/tools/read-tool-output.d.ts +7 -0
- package/dist/tools/read-tool-output.js +130 -0
- package/dist/tools/research/generate-analogy-report.d.ts +10 -26
- package/dist/tools/research/generate-analogy-report.js +76 -163
- package/dist/tools/research/generate-plan.d.ts +3 -0
- package/dist/tools/research/generate-plan.js +4 -1
- package/dist/tools/research/literature-reviewer.d.ts +3 -0
- package/dist/tools/research/literature-reviewer.js +3 -0
- package/dist/tools/sandbox/report-blocker.d.ts +18 -5
- package/dist/tools/sandbox/report-blocker.js +54 -6
- package/dist/tools/sandbox/submit-file-metadata.d.ts +30 -0
- package/dist/tools/sandbox/submit-file-metadata.js +67 -0
- package/dist/tools/start-report-session.d.ts +1 -3
- package/dist/tools/start-report-session.js +0 -2
- package/dist/tools/workspace/execute-command.js +7 -4
- package/dist/tools/workspace/result-bounds.d.ts +4 -4
- package/dist/tools/workspace/result-bounds.js +6 -5
- package/dist/tools/workspace/workspace-search.d.ts +1 -1
- package/dist/workflows/execute-analysis.d.ts +3 -0
- package/dist/workflows/execute-analysis.js +1 -0
- package/dist/workflows/sandbox-step.d.ts +30 -9
- package/dist/workflows/sandbox-step.js +37 -8
- package/package.json +9 -9
- package/dist/providers/anthropic.d.ts +0 -25
- package/dist/providers/anthropic.js +0 -28
package/dist/loop/run-agent.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ import { type FinishReason } from "ai";
|
|
|
2
2
|
import type { AgentSession } from "../auth/types.js";
|
|
3
3
|
import type { UsageRecorder } from "../billing/usage-recorder.js";
|
|
4
4
|
import type { Logger } from "../lib/logger.js";
|
|
5
|
-
import
|
|
5
|
+
import { type CompactionPolicy } from "./compaction.js";
|
|
6
|
+
import type { AgentChat, ChatRequest, ChatResponse, PromptCachePolicy, ReasoningPolicy } from "../providers/types.js";
|
|
6
7
|
import { type AskApproval, type AskRequest } from "../tools/approval/contract.js";
|
|
7
8
|
import { type AgentRunUsage } from "./metrics.js";
|
|
9
|
+
import { type ToolBudget, type ToolMask } from "./tool-mask.js";
|
|
10
|
+
import { type ToolOutputStore } from "./tool-output.js";
|
|
8
11
|
import type { AgentDefinition, EmitFn, LoopMessage, RunStep } from "./types.js";
|
|
9
12
|
export interface AgentFinish {
|
|
10
13
|
readonly reason: FinishReason | "aborted" | "max_iterations" | "denied";
|
|
@@ -31,6 +34,19 @@ export interface RunAgentResult {
|
|
|
31
34
|
readonly messages: LoopMessage[];
|
|
32
35
|
readonly finish: AgentFinish;
|
|
33
36
|
}
|
|
37
|
+
/** A request that the provider refused for its content: the HTTP status and the text of the provider error. */
|
|
38
|
+
export interface RequestRefusal {
|
|
39
|
+
readonly status: number;
|
|
40
|
+
readonly message: string;
|
|
41
|
+
}
|
|
42
|
+
/** The result of a segment. A segment that ends on a refusal of its request carries the refusal. */
|
|
43
|
+
export interface SegmentResult extends RunAgentResult {
|
|
44
|
+
readonly refusal?: RequestRefusal;
|
|
45
|
+
}
|
|
46
|
+
/** The messages that the loop appended after the last call of the round sink. */
|
|
47
|
+
export interface AgentRound {
|
|
48
|
+
readonly messages: readonly LoopMessage[];
|
|
49
|
+
}
|
|
34
50
|
export interface StepNameFormatter {
|
|
35
51
|
llm(iteration: number): string;
|
|
36
52
|
tool(toolName: string, toolUseId: string): string;
|
|
@@ -40,6 +56,17 @@ export interface RunAgentOptions {
|
|
|
40
56
|
readonly provider: AgentChat;
|
|
41
57
|
readonly signal: AbortSignal;
|
|
42
58
|
readonly emit: EmitFn;
|
|
59
|
+
/**
|
|
60
|
+
* The round sink. The loop awaits it before each model request, at each exit, and before a throw.
|
|
61
|
+
* A durable loop passes no sink, because DBOS replays the loop body.
|
|
62
|
+
*/
|
|
63
|
+
readonly onRound?: (round: AgentRound) => Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* The compaction policy. Each request then sends the view of the transcript, and the loop compacts
|
|
66
|
+
* before a task request whose view passes the budget. A durable loop passes no policy, because
|
|
67
|
+
* `recordsAfter` reads the database outside a step.
|
|
68
|
+
*/
|
|
69
|
+
readonly compaction?: CompactionPolicy;
|
|
43
70
|
/**
|
|
44
71
|
* Per-turn user-approval seam threaded into every tool's `ToolContext` as
|
|
45
72
|
* `ctx.ask`. A conversation tool calls it to pause for an explicit user
|
|
@@ -53,8 +80,10 @@ export interface RunAgentOptions {
|
|
|
53
80
|
readonly runStep: RunStep;
|
|
54
81
|
readonly formatStepName?: StepNameFormatter;
|
|
55
82
|
readonly isFatalLoopError?: (err: unknown) => boolean;
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
83
|
+
/**
|
|
84
|
+
* Tool choice for every request of this run: part of the prefix that the
|
|
85
|
+
* prompt cache and a signed thinking block bind to.
|
|
86
|
+
*/
|
|
58
87
|
readonly toolChoice?: ChatRequest["toolChoice"];
|
|
59
88
|
/**
|
|
60
89
|
* Optional outcome predicate for loop-driving agents whose result is
|
|
@@ -62,6 +91,13 @@ export interface RunAgentOptions {
|
|
|
62
91
|
* dispatch round, once every sibling tool result has been appended.
|
|
63
92
|
*/
|
|
64
93
|
readonly resolved?: () => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Tools allowed to run per request. The full tool set stays declared either
|
|
96
|
+
* way, since it is part of the cache/thinking-block prefix.
|
|
97
|
+
*/
|
|
98
|
+
readonly toolMask?: ToolMask;
|
|
99
|
+
/** Max calls per tool for this run; a call in the same round counts against the budget too. */
|
|
100
|
+
readonly toolBudget?: ToolBudget;
|
|
65
101
|
/**
|
|
66
102
|
* Prompt-cache policy for every LLM call this run makes. Defaults to
|
|
67
103
|
* `DEFAULT_PROMPT_CACHE` (5m) — an agent loop always re-sends its prefix, so
|
|
@@ -75,16 +111,9 @@ export interface RunAgentOptions {
|
|
|
75
111
|
*/
|
|
76
112
|
readonly promptCache?: PromptCachePolicy;
|
|
77
113
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* deeper turn costs in tokens. The provider package resolves the name for
|
|
82
|
-
* the model that it is bound to.
|
|
83
|
-
*
|
|
84
|
-
* The policy lives here, on the run, rather than on the provider, for the
|
|
85
|
-
* same reason that the cache policy does: a one-shot LLM call elsewhere has
|
|
86
|
-
* its own depth needs and must not inherit the depth of a loop. A host on a
|
|
87
|
-
* model with no reasoning support passes `"provider-default"`.
|
|
114
|
+
* The reasoning effort for each LLM call of this run, the forced wrap-up
|
|
115
|
+
* included. Anthropic discards its message cache when the top-level
|
|
116
|
+
* effort changes, so the run must send the same value, or none, throughout.
|
|
88
117
|
*/
|
|
89
118
|
readonly reasoning?: ReasoningPolicy;
|
|
90
119
|
/**
|
|
@@ -104,6 +133,8 @@ export interface RunAgentOptions {
|
|
|
104
133
|
* and it logs the reason of an `err` when the result arrives.
|
|
105
134
|
*/
|
|
106
135
|
readonly usageRecorder?: UsageRecorder;
|
|
136
|
+
/** Keeps the text of each cut tool result. A run with no store cuts, and it keeps nothing. */
|
|
137
|
+
readonly toolOutputStore?: ToolOutputStore;
|
|
107
138
|
/**
|
|
108
139
|
* The turn's usage accumulator, supplied by whatever ran this loop as part
|
|
109
140
|
* of a larger turn (a sub-agent-running tool passes `ctx.turnUsage`). A run
|
|
@@ -121,5 +152,72 @@ export interface RunAgentOptions {
|
|
|
121
152
|
*/
|
|
122
153
|
readonly invocationId?: string;
|
|
123
154
|
}
|
|
155
|
+
/** A run that receives no turn accumulator is the turn's root. See `RunAgentOptions.turnUsage`. */
|
|
156
|
+
export declare const isTurnRoot: (opts: RunAgentOptions) => boolean;
|
|
124
157
|
export declare function runAgent(agent: AgentDefinition, initial: readonly LoopMessage[], session: AgentSession, opts: RunAgentOptions): Promise<RunAgentResult>;
|
|
158
|
+
/** The harness request of the wrap-up at the iteration cap. */
|
|
159
|
+
export declare const WRAP_UP_REQUEST = "You reached the limit of tool rounds for this run, thus no tool can run now. Answer in text with the results that you have.";
|
|
160
|
+
/** The cap of wrap-up requests: one answer, and one more request after a refused call. */
|
|
161
|
+
export declare const WRAP_UP_MAX_REQUESTS = 2;
|
|
162
|
+
/** One stretch of model requests of a conversation, under one mask. */
|
|
163
|
+
export interface LoopSegment {
|
|
164
|
+
/** The tools that can run for each request of the segment. Absent lets each declared tool run. */
|
|
165
|
+
readonly mask: ToolMask | undefined;
|
|
166
|
+
readonly maxRequests: number;
|
|
167
|
+
readonly stepNames: StepNameFormatter;
|
|
168
|
+
/** The `index` of the first request of the segment in its `iteration` events. */
|
|
169
|
+
readonly firstIndex: number;
|
|
170
|
+
/** A harness request that the segment appends, as a synthetic user message, before its first request. */
|
|
171
|
+
readonly requestText?: string;
|
|
172
|
+
/**
|
|
173
|
+
* The segment runs after the iteration cap: its requests do not count as
|
|
174
|
+
* iterations, and the last one always ends the run, whatever its reply.
|
|
175
|
+
*/
|
|
176
|
+
readonly closesCappedRun?: boolean;
|
|
177
|
+
/** The loop compacts before a request of the segment whose view passes the budget of the policy. */
|
|
178
|
+
readonly checksBudget?: boolean;
|
|
179
|
+
/** A refusal of a request, a `provider` error with the status `400` or `413`, ends the segment with no new message. */
|
|
180
|
+
readonly endsOnRequestRefusal?: boolean;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* One conversation, open for its segments. Each segment extends the same
|
|
184
|
+
* prefix (system prompt, tools, tool choice) as the one before it.
|
|
185
|
+
*/
|
|
186
|
+
export interface OpenLoop {
|
|
187
|
+
/** Run one segment: the result of the run when a reply ends it, or `"capped"` when the segment used its cap. */
|
|
188
|
+
runSegment(segment: LoopSegment): Promise<SegmentResult | "capped">;
|
|
189
|
+
/** End a run after its last segment used its cap. */
|
|
190
|
+
endCapped(): Promise<RunAgentResult>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Open the loop over one conversation. `metricAgentId` is the id that usage
|
|
194
|
+
* and run metrics count under, which is not always `agent.id`.
|
|
195
|
+
*/
|
|
196
|
+
export declare function openLoop(agent: AgentDefinition, initial: readonly LoopMessage[], session: AgentSession, opts: RunAgentOptions, metricAgentId: string): OpenLoop;
|
|
197
|
+
/** What one completed LLM call is accounted under. */
|
|
198
|
+
export interface ChatCallAccounting {
|
|
199
|
+
readonly session: AgentSession;
|
|
200
|
+
readonly agentId: string;
|
|
201
|
+
readonly callPath: readonly string[];
|
|
202
|
+
/**
|
|
203
|
+
* The deterministic name inside the record key, for example `llm-{n}` for
|
|
204
|
+
* a loop call or `adhoc-route` for a direct call.
|
|
205
|
+
*/
|
|
206
|
+
readonly stepName: string;
|
|
207
|
+
/** The id of the tool call that makes the call, when the call runs inside a tool dispatch. */
|
|
208
|
+
readonly invocationId?: string;
|
|
209
|
+
readonly usageRecorder: UsageRecorder;
|
|
210
|
+
/** The sink that the notice helper logs the reason of a recorder `err` to. */
|
|
211
|
+
readonly logger: Logger;
|
|
212
|
+
/** The accumulators that the usage of the call folds into, for example the run total and the turn total. */
|
|
213
|
+
readonly rollups: readonly AgentRunUsage[];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Called at the fold point, before any run-ending branch, so an aborted or
|
|
217
|
+
* dead run is still accounted. Token counters grow inside the call's step
|
|
218
|
+
* body, not here, because a replay re-delivers the stored reply to this
|
|
219
|
+
* function too; the record re-sends under the same idempotency key, which an
|
|
220
|
+
* upserting sink counts once.
|
|
221
|
+
*/
|
|
222
|
+
export declare function accountForChatCall(reply: ChatResponse, call: ChatCallAccounting): void;
|
|
125
223
|
export declare function finalText(messages: readonly LoopMessage[]): string;
|