@link-assistant/agent 0.13.5 → 0.14.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/package.json +1 -1
- package/src/flag/flag.ts +34 -0
- package/src/index.js +19 -17
- package/src/provider/provider.ts +23 -1
- package/src/session/message-v2.ts +19 -0
- package/src/session/processor.ts +17 -0
- package/src/session/summary.ts +11 -0
package/package.json
CHANGED
package/src/flag/flag.ts
CHANGED
|
@@ -82,6 +82,40 @@ export namespace Flag {
|
|
|
82
82
|
GENERATE_TITLE = value;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// Output response model information in step-finish parts
|
|
86
|
+
// Enabled by default - includes model info (providerID, requestedModelID, respondedModelID) in output
|
|
87
|
+
// Can be disabled with AGENT_OUTPUT_RESPONSE_MODEL=false
|
|
88
|
+
// See: https://github.com/link-assistant/agent/issues/179
|
|
89
|
+
export let OUTPUT_RESPONSE_MODEL = (() => {
|
|
90
|
+
const value = (
|
|
91
|
+
getEnv(
|
|
92
|
+
'LINK_ASSISTANT_AGENT_OUTPUT_RESPONSE_MODEL',
|
|
93
|
+
'AGENT_OUTPUT_RESPONSE_MODEL'
|
|
94
|
+
) ?? ''
|
|
95
|
+
).toLowerCase();
|
|
96
|
+
if (value === 'false' || value === '0') return false;
|
|
97
|
+
return true; // Default to true
|
|
98
|
+
})();
|
|
99
|
+
|
|
100
|
+
// Allow setting output-response-model mode programmatically (e.g., from CLI --output-response-model flag)
|
|
101
|
+
export function setOutputResponseModel(value: boolean) {
|
|
102
|
+
OUTPUT_RESPONSE_MODEL = value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Session summarization configuration
|
|
106
|
+
// When disabled, session summaries will not be generated
|
|
107
|
+
// This saves tokens and prevents rate limit issues with free tier models
|
|
108
|
+
// See: https://github.com/link-assistant/agent/issues/179
|
|
109
|
+
export let SUMMARIZE_SESSION = truthyCompat(
|
|
110
|
+
'LINK_ASSISTANT_AGENT_SUMMARIZE_SESSION',
|
|
111
|
+
'AGENT_SUMMARIZE_SESSION'
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Allow setting summarize-session mode programmatically (e.g., from CLI --summarize-session flag)
|
|
115
|
+
export function setSummarizeSession(value: boolean) {
|
|
116
|
+
SUMMARIZE_SESSION = value;
|
|
117
|
+
}
|
|
118
|
+
|
|
85
119
|
// Retry timeout configuration
|
|
86
120
|
// Maximum total time to keep retrying for the same error type (default: 7 days in seconds)
|
|
87
121
|
// For different error types, the timer resets
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { Flag } from './flag/flag.ts';
|
|
3
3
|
import { setProcessName } from './cli/process-name.ts';
|
|
4
4
|
setProcessName('agent');
|
|
5
|
-
|
|
6
5
|
import { Server } from './server/server.ts';
|
|
7
6
|
import { Instance } from './project/instance.ts';
|
|
8
7
|
import { Log } from './util/log.ts';
|
|
@@ -743,6 +742,16 @@ async function main() {
|
|
|
743
742
|
type: 'number',
|
|
744
743
|
description:
|
|
745
744
|
'Maximum total retry time in seconds for rate limit errors (default: 604800 = 7 days)',
|
|
745
|
+
})
|
|
746
|
+
.option('output-response-model', {
|
|
747
|
+
type: 'boolean',
|
|
748
|
+
description: 'Include model info in step_finish output',
|
|
749
|
+
default: true,
|
|
750
|
+
})
|
|
751
|
+
.option('summarize-session', {
|
|
752
|
+
type: 'boolean',
|
|
753
|
+
description: 'Generate AI session summaries',
|
|
754
|
+
default: false,
|
|
746
755
|
}),
|
|
747
756
|
handler: async (argv) => {
|
|
748
757
|
// Check both CLI flag and environment variable for compact JSON mode
|
|
@@ -906,37 +915,30 @@ async function main() {
|
|
|
906
915
|
await runAgentMode(argv, request);
|
|
907
916
|
},
|
|
908
917
|
})
|
|
909
|
-
// Initialize logging early for all CLI commands
|
|
910
|
-
// This prevents debug output from appearing in CLI unless --verbose is used
|
|
918
|
+
// Initialize logging and flags early for all CLI commands
|
|
911
919
|
.middleware(async (argv) => {
|
|
912
|
-
// Set global compact JSON setting (CLI flag or environment variable)
|
|
913
920
|
const isCompact = argv['compact-json'] === true || Flag.COMPACT_JSON();
|
|
914
921
|
if (isCompact) {
|
|
915
922
|
setCompactJson(true);
|
|
916
923
|
}
|
|
917
|
-
|
|
918
|
-
// Set verbose flag if requested
|
|
919
924
|
if (argv.verbose) {
|
|
920
925
|
Flag.setVerbose(true);
|
|
921
926
|
}
|
|
922
|
-
|
|
923
|
-
// Set dry-run flag if requested
|
|
924
927
|
if (argv['dry-run']) {
|
|
925
928
|
Flag.setDryRun(true);
|
|
926
929
|
}
|
|
927
|
-
|
|
928
|
-
// Set generate-title flag if explicitly enabled
|
|
929
|
-
// Default is false to save tokens and prevent rate limit issues
|
|
930
|
-
// See: https://github.com/link-assistant/agent/issues/157
|
|
931
930
|
if (argv['generate-title'] === true) {
|
|
932
931
|
Flag.setGenerateTitle(true);
|
|
933
932
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
933
|
+
// output-response-model is enabled by default, only set if explicitly disabled
|
|
934
|
+
if (argv['output-response-model'] === false) {
|
|
935
|
+
Flag.setOutputResponseModel(false);
|
|
936
|
+
}
|
|
937
|
+
if (argv['summarize-session'] === true) {
|
|
938
|
+
Flag.setSummarizeSession(true);
|
|
939
|
+
}
|
|
938
940
|
await Log.init({
|
|
939
|
-
print: Flag.OPENCODE_VERBOSE,
|
|
941
|
+
print: Flag.OPENCODE_VERBOSE,
|
|
940
942
|
level: Flag.OPENCODE_VERBOSE ? 'DEBUG' : 'INFO',
|
|
941
943
|
compactJson: isCompact,
|
|
942
944
|
});
|
package/src/provider/provider.ts
CHANGED
|
@@ -1297,11 +1297,25 @@ export namespace Provider {
|
|
|
1297
1297
|
}
|
|
1298
1298
|
}
|
|
1299
1299
|
|
|
1300
|
+
/**
|
|
1301
|
+
* Get a small/cheap model for auxiliary tasks like title generation and summarization.
|
|
1302
|
+
* This is NOT the primary model for user requests - it's used for background tasks.
|
|
1303
|
+
*
|
|
1304
|
+
* Note: Logs from this function may show a different model than what the user specified.
|
|
1305
|
+
* This is by design - we use cheaper models for auxiliary tasks to save tokens/costs.
|
|
1306
|
+
*
|
|
1307
|
+
* @see https://github.com/link-assistant/agent/issues/179
|
|
1308
|
+
*/
|
|
1300
1309
|
export async function getSmallModel(providerID: string) {
|
|
1301
1310
|
const cfg = await Config.get();
|
|
1302
1311
|
|
|
1303
1312
|
if (cfg.small_model) {
|
|
1304
1313
|
const parsed = parseModel(cfg.small_model);
|
|
1314
|
+
log.info(() => ({
|
|
1315
|
+
message: 'using configured small_model for auxiliary task',
|
|
1316
|
+
modelID: parsed.modelID,
|
|
1317
|
+
providerID: parsed.providerID,
|
|
1318
|
+
}));
|
|
1305
1319
|
return getModel(parsed.providerID, parsed.modelID);
|
|
1306
1320
|
}
|
|
1307
1321
|
|
|
@@ -1339,7 +1353,15 @@ export namespace Provider {
|
|
|
1339
1353
|
}
|
|
1340
1354
|
for (const item of priority) {
|
|
1341
1355
|
for (const model of Object.keys(provider.info.models)) {
|
|
1342
|
-
if (model.includes(item))
|
|
1356
|
+
if (model.includes(item)) {
|
|
1357
|
+
log.info(() => ({
|
|
1358
|
+
message: 'selected small model for auxiliary task',
|
|
1359
|
+
modelID: model,
|
|
1360
|
+
providerID,
|
|
1361
|
+
hint: 'This model is used for title/summary generation, not primary requests',
|
|
1362
|
+
}));
|
|
1363
|
+
return getModel(providerID, model);
|
|
1364
|
+
}
|
|
1343
1365
|
}
|
|
1344
1366
|
}
|
|
1345
1367
|
}
|
|
@@ -224,6 +224,22 @@ export namespace MessageV2 {
|
|
|
224
224
|
});
|
|
225
225
|
export type StepStartPart = z.infer<typeof StepStartPart>;
|
|
226
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Model information for output parts.
|
|
229
|
+
* Included when --output-response-model flag is enabled.
|
|
230
|
+
* @see https://github.com/link-assistant/agent/issues/179
|
|
231
|
+
*/
|
|
232
|
+
export const ModelInfo = z
|
|
233
|
+
.object({
|
|
234
|
+
providerID: z.string(),
|
|
235
|
+
requestedModelID: z.string(),
|
|
236
|
+
respondedModelID: z.string().optional(),
|
|
237
|
+
})
|
|
238
|
+
.meta({
|
|
239
|
+
ref: 'ModelInfo',
|
|
240
|
+
});
|
|
241
|
+
export type ModelInfo = z.infer<typeof ModelInfo>;
|
|
242
|
+
|
|
227
243
|
export const StepFinishPart = PartBase.extend({
|
|
228
244
|
type: z.literal('step-finish'),
|
|
229
245
|
reason: z.string(),
|
|
@@ -238,6 +254,9 @@ export namespace MessageV2 {
|
|
|
238
254
|
write: z.number(),
|
|
239
255
|
}),
|
|
240
256
|
}),
|
|
257
|
+
// Model info included when --output-response-model is enabled
|
|
258
|
+
// @see https://github.com/link-assistant/agent/issues/179
|
|
259
|
+
model: ModelInfo.optional(),
|
|
241
260
|
}).meta({
|
|
242
261
|
ref: 'StepFinishPart',
|
|
243
262
|
});
|
package/src/session/processor.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { SessionSummary } from './summary';
|
|
|
16
16
|
import { Bus } from '../bus';
|
|
17
17
|
import { SessionRetry } from './retry';
|
|
18
18
|
import { SessionStatus } from './status';
|
|
19
|
+
import { Flag } from '../flag/flag';
|
|
19
20
|
|
|
20
21
|
export namespace SessionProcessor {
|
|
21
22
|
const DOOM_LOOP_THRESHOLD = 3;
|
|
@@ -261,6 +262,21 @@ export namespace SessionProcessor {
|
|
|
261
262
|
input.assistantMessage.finish = finishReason;
|
|
262
263
|
input.assistantMessage.cost += usage.cost;
|
|
263
264
|
input.assistantMessage.tokens = usage.tokens;
|
|
265
|
+
|
|
266
|
+
// Build model info if --output-response-model flag is enabled
|
|
267
|
+
// @see https://github.com/link-assistant/agent/issues/179
|
|
268
|
+
const modelInfo: MessageV2.ModelInfo | undefined =
|
|
269
|
+
Flag.OUTPUT_RESPONSE_MODEL
|
|
270
|
+
? {
|
|
271
|
+
providerID: input.providerID,
|
|
272
|
+
requestedModelID: input.model.id,
|
|
273
|
+
// Get respondedModelID from finish-step response if available
|
|
274
|
+
// AI SDK includes response.modelId when available from provider
|
|
275
|
+
respondedModelID:
|
|
276
|
+
(value as any).response?.modelId ?? undefined,
|
|
277
|
+
}
|
|
278
|
+
: undefined;
|
|
279
|
+
|
|
264
280
|
await Session.updatePart({
|
|
265
281
|
id: Identifier.ascending('part'),
|
|
266
282
|
reason: finishReason,
|
|
@@ -270,6 +286,7 @@ export namespace SessionProcessor {
|
|
|
270
286
|
type: 'step-finish',
|
|
271
287
|
tokens: usage.tokens,
|
|
272
288
|
cost: usage.cost,
|
|
289
|
+
model: modelInfo,
|
|
273
290
|
});
|
|
274
291
|
await Session.updateMessage(input.assistantMessage);
|
|
275
292
|
if (snapshot) {
|
package/src/session/summary.ts
CHANGED
|
@@ -13,6 +13,7 @@ import path from 'path';
|
|
|
13
13
|
import { Instance } from '../project/instance';
|
|
14
14
|
import { Storage } from '../storage/storage';
|
|
15
15
|
import { Bus } from '../bus';
|
|
16
|
+
import { Flag } from '../flag/flag';
|
|
16
17
|
|
|
17
18
|
export namespace SessionSummary {
|
|
18
19
|
const log = Log.create({ service: 'session.summary' });
|
|
@@ -79,6 +80,16 @@ export namespace SessionSummary {
|
|
|
79
80
|
};
|
|
80
81
|
await Session.updateMessage(userMsg);
|
|
81
82
|
|
|
83
|
+
// Skip AI-powered summarization if disabled (default)
|
|
84
|
+
// See: https://github.com/link-assistant/agent/issues/179
|
|
85
|
+
if (!Flag.SUMMARIZE_SESSION) {
|
|
86
|
+
log.info(() => ({
|
|
87
|
+
message: 'session summarization disabled',
|
|
88
|
+
hint: 'Enable with --summarize-session flag or AGENT_SUMMARIZE_SESSION=true',
|
|
89
|
+
}));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
const assistantMsg = messages.find((m) => m.info.role === 'assistant')!
|
|
83
94
|
.info as MessageV2.Assistant;
|
|
84
95
|
const small = await Provider.getSmallModel(assistantMsg.providerID);
|