@swirls/looms 0.12.2 → 0.12.4
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 +16 -0
- package/dist/agent/definitions.d.ts +5 -0
- package/dist/agent/effects.d.ts +1 -0
- package/dist/agent/effects.js +9 -2
- package/dist/agent/module.d.ts +652 -650
- package/dist/agent/stop-when.d.ts +5 -0
- package/dist/agent/stop-when.js +1 -0
- package/dist/agent/threads.js +9 -0
- package/dist/agent/types.d.ts +6 -0
- package/dist/core/module.d.ts +5 -2
- package/dist/core/module.js +3 -0
- package/dist/runtime/local-effect-executor.js +15 -7
- package/dist/runtime/runtime.js +3 -1
- package/dist/runtime/wake-engine.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @swirls/looms
|
|
2
2
|
|
|
3
|
+
## 0.12.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b8b1759: Count `maxTurns` per user message for conversational agents. The turn counter ran over the whole conversation, so a chat with `maxTurns: 3` failed with "Max turns exceeded" on its fourth reply. A conversational agent now counts model turns from its latest user message (or steer), so the limit bounds the work spent on one reply. Agents that are not conversational still count every turn of the run.
|
|
8
|
+
- b8b1759: Make `stopAgentTurn()` and an interrupting `steer()` abort the in-flight model call when sent without a thread id. The signal was recorded on the root thread, but the interrupt lookup only matched an explicit `threadId`, so the adapter's `signal` never aborted and the full reply was appended after the stop. A signal without a thread id now interrupts the root thread and its children, for conversational agents and agent sessions alike.
|
|
9
|
+
- b8b1759: Count `stopWhen` steps per user message for conversational agents. `stopWhen` received the thread's lifetime turn number, so `stepCountIs(8)` on a conversational agent stopped every turn after the eighth and dropped its tool calls. The `turn` passed to `stopWhen` now counts from the latest user message for a conversational agent, the same way `maxTurns` does. Other agents are unchanged.
|
|
10
|
+
- b8b1759: Keep text deltas that were streamed just before a turn was stopped. Live events are written in the background, and a wake whose only attempt was aborted released the run without flushing them, so a delta emitted moments before `stopAgentTurn()` could be missing from the log. The wake now flushes pending live events before it parks.
|
|
11
|
+
- b8b1759: Keep a run alive when a message follows a stopped agent turn. A model call that was stopped mid-stream could emit one more text delta after its turn was abandoned. That late write failed, and the failure stuck to the run, so the next turn's first `onTextDelta` threw "Cannot append live events without a store" and the run failed. Live events from an attempt that has been aborted or has finished are now dropped.
|
|
12
|
+
|
|
13
|
+
## 0.12.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 04d546e: `onEffect` and `onAdmit` accept an effect definition that requires host services. Wrapping `callLlmEffect` in middleware, as in `onEffect(callLlmEffect, handler)`, was a type error because the definition's service requirements did not match the parameter's default. The functions now infer those requirements from the definition.
|
|
18
|
+
|
|
3
19
|
## 0.12.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -114,7 +114,12 @@ export interface AgentDefinition<TName extends string = string, TInput = JsonVal
|
|
|
114
114
|
resolveTools?(ctx: AgentToolResolutionContext<TInput>): Promise<readonly AgentToolEntry[]> | readonly AgentToolEntry[];
|
|
115
115
|
/** Shrinks the conversation after the model reports a context overflow. */
|
|
116
116
|
readonly compact?: AgentCompactor;
|
|
117
|
+
/**
|
|
118
|
+
* Most model turns the agent may take before its thread fails. Default 20. A conversational
|
|
119
|
+
* agent counts from its latest user message, so the limit bounds one reply.
|
|
120
|
+
*/
|
|
117
121
|
readonly maxTurns?: number;
|
|
122
|
+
/** Keep the run open after a reply so the next user message starts another turn. */
|
|
118
123
|
readonly conversational?: boolean;
|
|
119
124
|
readonly stopWhen?: StopWhen;
|
|
120
125
|
runTurn?(ctx: AgentTurnContext<TInput>): Promise<AgentTurnResult<TOutput>> | AgentTurnResult<TOutput>;
|
package/dist/agent/effects.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { LlmTag } from './llm';
|
|
|
5
5
|
import { type ToolCall } from './types';
|
|
6
6
|
export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
|
|
7
7
|
readonly turn: number;
|
|
8
|
+
readonly messageTurn?: number | undefined;
|
|
8
9
|
readonly definitionName?: string | undefined;
|
|
9
10
|
readonly definitionVersion: string;
|
|
10
11
|
readonly messages?: readonly {
|
package/dist/agent/effects.js
CHANGED
|
@@ -8,6 +8,8 @@ import { toolSpecs } from './tool-schema.js';
|
|
|
8
8
|
import { MessageSchema, ToolCallSchema } from './types.js';
|
|
9
9
|
const CallLlmInput = Schema.Struct({
|
|
10
10
|
turn: Schema.Finite,
|
|
11
|
+
/** Turns since the latest user message, this one included. */
|
|
12
|
+
messageTurn: Schema.optional(Schema.Finite),
|
|
11
13
|
definitionName: Schema.optional(Schema.String),
|
|
12
14
|
definitionVersion: Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed(DEFAULT_DEFINITION_VERSION))),
|
|
13
15
|
messages: Schema.optional(Schema.Array(MessageSchema)),
|
|
@@ -78,6 +80,7 @@ export const callLlmEffect = agentModule.effect({
|
|
|
78
80
|
input: CallLlmInput,
|
|
79
81
|
execute: (input, ctx) => runCallLlm({
|
|
80
82
|
turn: input.turn,
|
|
83
|
+
messageTurn: input.messageTurn ?? input.turn,
|
|
81
84
|
definitionName: input.definitionName,
|
|
82
85
|
definitionVersion: input.definitionVersion,
|
|
83
86
|
messages: [...(input.messages ?? [])],
|
|
@@ -108,7 +111,11 @@ function runCallLlm(args) {
|
|
|
108
111
|
},
|
|
109
112
|
];
|
|
110
113
|
}
|
|
111
|
-
|
|
114
|
+
// A conversation has no natural end, so its limits (`maxTurns`, and the turn `stopWhen`
|
|
115
|
+
// sees) count the turns spent answering one message. Any other agent runs one task and
|
|
116
|
+
// counts every turn against it.
|
|
117
|
+
const countedTurn = definition.conversational ? args.messageTurn : turn;
|
|
118
|
+
if (countedTurn > (definition.maxTurns ?? 20)) {
|
|
112
119
|
return [
|
|
113
120
|
{
|
|
114
121
|
type: 'runtime.thread.failed',
|
|
@@ -201,7 +208,7 @@ function runCallLlm(args) {
|
|
|
201
208
|
}));
|
|
202
209
|
const toolCalls = result.toolCalls ?? result.message.toolCalls ?? [];
|
|
203
210
|
const shouldStop = definition.stopWhen?.({
|
|
204
|
-
turn,
|
|
211
|
+
turn: countedTurn,
|
|
205
212
|
maxTurns: definition.maxTurns ?? 20,
|
|
206
213
|
messages: currentMessages,
|
|
207
214
|
toolCalls,
|