agents-relay 1.0.104 → 1.0.105
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/reconciler-review.js +16 -3
- package/dist/reviewer-routing.js +3 -17
- package/dist/routing-policy.js +20 -7
- package/dist/worker-routing.js +38 -31
- package/package.json +1 -1
- package/skills/agents-relay/agents/planner.agent.md +3 -3
- package/skills/agents-relay/contracts/task-job-contract.md +8 -7
|
@@ -109,9 +109,22 @@ export class ReconcilerReviewBase extends ReconcilerRuntimeBase {
|
|
|
109
109
|
const registered = await this.store.listAgents();
|
|
110
110
|
const candidates = workerCandidates(this.options.adapters, registered, usage);
|
|
111
111
|
for (const task of job.tasks.filter(item => item.kind !== 'planner' && item.agentName !== 'reviewer' && item.adapter !== 'orchestrator' && ['QUEUED', 'BLOCKED'].includes(item.state) && item.output && !item.workerSelection && (item.workerRequirements || item.planningSource === 'model-planner'))) {
|
|
112
|
-
const requirements = task.workerRequirements ?? { capabilities:
|
|
113
|
-
const taskFacts = {
|
|
114
|
-
|
|
112
|
+
const requirements = task.workerRequirements ?? { capabilities: [] };
|
|
113
|
+
const taskFacts = {
|
|
114
|
+
id: task.id,
|
|
115
|
+
kind: task.kind ?? 'work',
|
|
116
|
+
storySize: task.storySize ?? 'M',
|
|
117
|
+
agentName: task.agentName ?? null,
|
|
118
|
+
input: task.input,
|
|
119
|
+
attachments: task.attachments ?? [],
|
|
120
|
+
output: task.output ?? null,
|
|
121
|
+
};
|
|
122
|
+
const routedWorker = await routeWorker(candidates, requirements, {
|
|
123
|
+
decisionEngine: this.options.decisionEngine,
|
|
124
|
+
decisionMode: this.options.decisionMode,
|
|
125
|
+
taskFacts,
|
|
126
|
+
usage,
|
|
127
|
+
});
|
|
115
128
|
const models = await discoverModelCandidates(routedWorker.candidate, registered, usage);
|
|
116
129
|
const routingConstraints = task.routing ? { provider: task.routing.provider, model: task.routing.model, profile: task.routing.profile, reasoning: task.routing.reasoning } : undefined;
|
|
117
130
|
const routedModel = await routeModel(routedWorker.candidate, models, { decisionEngine: this.options.decisionEngine, decisionMode: this.options.decisionMode, taskFacts, constraints: routingConstraints, auditStore: this.options.decisionAuditStore, auditTask: task });
|
package/dist/reviewer-routing.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
function satisfies(candidate, requirements) {
|
|
2
|
-
if (candidate.availability
|
|
2
|
+
if (candidate.availability === 'offline')
|
|
3
3
|
return false;
|
|
4
|
-
if (candidate.
|
|
5
|
-
return false;
|
|
6
|
-
if (!requirements)
|
|
7
|
-
return true;
|
|
8
|
-
if (!requirements.capabilities.every(capability => candidate.capabilities.includes(capability)))
|
|
9
|
-
return false;
|
|
10
|
-
if (requirements.runtime && candidate.runtime !== requirements.runtime)
|
|
11
|
-
return false;
|
|
12
|
-
if (requirements.taskKind && candidate.taskKind !== requirements.taskKind)
|
|
13
|
-
return false;
|
|
14
|
-
if (requirements.trustDomain && !candidate.trustDomains?.includes(requirements.trustDomain))
|
|
15
|
-
return false;
|
|
16
|
-
if (requirements.region && candidate.region !== requirements.region)
|
|
17
|
-
return false;
|
|
18
|
-
if (requirements.labels && Object.entries(requirements.labels).some(([key, value]) => candidate.labels?.[key] !== value))
|
|
4
|
+
if (requirements?.runtime && candidate.runtime !== requirements.runtime)
|
|
19
5
|
return false;
|
|
20
6
|
return true;
|
|
21
7
|
}
|
|
@@ -29,7 +15,7 @@ function producedRoutes(tasks) {
|
|
|
29
15
|
.filter(task => task.agentName !== 'reviewer' && task.routing)
|
|
30
16
|
.map(task => `${task.routing?.provider}\0${task.routing?.model}`));
|
|
31
17
|
}
|
|
32
|
-
/** Select a
|
|
18
|
+
/** Select a reviewer after authoritative worker constraints, then prefer execution diversity. */
|
|
33
19
|
export function selectReviewer(candidates, implementationTasks, requirements) {
|
|
34
20
|
const eligible = candidates.filter(candidate => satisfies(candidate, requirements));
|
|
35
21
|
if (eligible.length === 0)
|
package/dist/routing-policy.js
CHANGED
|
@@ -30,11 +30,7 @@ function safePolicy(value) {
|
|
|
30
30
|
export function policyPath(explicit) {
|
|
31
31
|
return explicit ?? process.env.AGENTS_RELAY_ROUTING_POLICY ?? join(process.cwd(), '.agents-relay-routing-policy.json');
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
return explicit ?? process.env.AGENTS_RELAY_MODEL_ROUTER_RULES ?? join(process.cwd(), '.agents-relay-model-router-rules.md');
|
|
35
|
-
}
|
|
36
|
-
export async function loadModelRouterRules(explicit) {
|
|
37
|
-
const path = modelRouterRulesPath(explicit);
|
|
33
|
+
async function loadRouterRules(path) {
|
|
38
34
|
try {
|
|
39
35
|
const text = await readFile(path, 'utf8');
|
|
40
36
|
return { path, hash: createHash('sha256').update(text).digest('hex'), text };
|
|
@@ -43,12 +39,29 @@ export async function loadModelRouterRules(explicit) {
|
|
|
43
39
|
return { path, hash: 'none', text: '' };
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
const path = modelRouterRulesPath(explicit);
|
|
42
|
+
async function saveRouterRules(path, text) {
|
|
48
43
|
await mkdir(dirname(path), { recursive: true });
|
|
49
44
|
await writeFile(path, text, 'utf8');
|
|
50
45
|
return { path, hash: createHash('sha256').update(text).digest('hex'), text };
|
|
51
46
|
}
|
|
47
|
+
export function modelRouterRulesPath(explicit) {
|
|
48
|
+
return explicit ?? process.env.AGENTS_RELAY_MODEL_ROUTER_RULES ?? join(process.cwd(), '.agents-relay-model-router-rules.md');
|
|
49
|
+
}
|
|
50
|
+
export function workerRouterRulesPath(explicit) {
|
|
51
|
+
return explicit ?? process.env.AGENTS_RELAY_WORKER_ROUTER_RULES ?? join(process.cwd(), '.agents-relay-worker-router-rules.md');
|
|
52
|
+
}
|
|
53
|
+
export async function loadModelRouterRules(explicit) {
|
|
54
|
+
return await loadRouterRules(modelRouterRulesPath(explicit));
|
|
55
|
+
}
|
|
56
|
+
export async function saveModelRouterRules(text, explicit) {
|
|
57
|
+
return await saveRouterRules(modelRouterRulesPath(explicit), text);
|
|
58
|
+
}
|
|
59
|
+
export async function loadWorkerRouterRules(explicit) {
|
|
60
|
+
return await loadRouterRules(workerRouterRulesPath(explicit));
|
|
61
|
+
}
|
|
62
|
+
export async function saveWorkerRouterRules(text, explicit) {
|
|
63
|
+
return await saveRouterRules(workerRouterRulesPath(explicit), text);
|
|
64
|
+
}
|
|
52
65
|
export async function loadRoutingPolicy(explicit, explicitRules) {
|
|
53
66
|
const path = policyPath(explicit);
|
|
54
67
|
const rules = await loadModelRouterRules(explicitRules);
|
package/dist/worker-routing.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { chooseWithDecision } from './decision.js';
|
|
2
|
+
import { loadWorkerRouterRules } from './routing-policy.js';
|
|
3
|
+
export const DEFAULT_WORKER_ROUTER_PRINCIPLES = [
|
|
4
|
+
'Worker Router chooses only the execution worker. Model Router chooses provider/model/profile after worker selection.',
|
|
5
|
+
'Prefer ChatGPT when both workers can execute the task because it does not consume Codex coding-plan tokens and normally has access to a stronger ChatGPT Sol model.',
|
|
6
|
+
'Prefer Codex when the task requires native/local execution or computer-use abilities that are unavailable through ChatGPT plus MacBridge.',
|
|
7
|
+
'Treat coding-plan/provider quota as decision context, not worker legality. Codex may still use another provider selected later by Model Router.',
|
|
8
|
+
'When Codex/OpenAI coding quota is scarce, prefer ChatGPT unless the Codex execution environment is necessary.',
|
|
9
|
+
].join('\n');
|
|
2
10
|
export function usageForProvider(snapshot, provider, now = Date.now()) {
|
|
3
11
|
const usage = snapshot?.providers.find(item => item.id === provider)?.usage;
|
|
4
12
|
if (usage?.available) {
|
|
@@ -39,15 +47,12 @@ export function workerCandidates(adapters, registered, snapshot) {
|
|
|
39
47
|
return adapters.filter(adapter => adapter.name !== 'orchestrator').flatMap(adapter => {
|
|
40
48
|
const workers = registered.filter(worker => worker.runtime.adapter === adapter.name);
|
|
41
49
|
return (workers.length > 0 ? workers : [undefined]).map(worker => {
|
|
42
|
-
const provider = worker?.runtime.provider ?? (adapter.name === 'chatgpt' ? 'chatgpt' :
|
|
43
|
-
const resource = usageForProvider(snapshot, provider);
|
|
50
|
+
const provider = worker?.runtime.provider ?? (adapter.name === 'chatgpt' ? 'chatgpt' : undefined);
|
|
51
|
+
const resource = provider ? usageForProvider(snapshot, provider) : {};
|
|
44
52
|
return {
|
|
45
53
|
workerId: worker?.id ?? adapter.id,
|
|
46
54
|
adapter: adapter.name,
|
|
47
|
-
capabilities: worker?.capabilities ?? [
|
|
48
|
-
...adapter.capabilities,
|
|
49
|
-
...(adapter.name === 'codex' ? ['local_repo', 'iterative_tools', 'long_running'] : ['web_session', 'attachments', 'interactive_ui', 'one_shot']),
|
|
50
|
-
],
|
|
55
|
+
capabilities: worker?.capabilities ?? [...adapter.capabilities],
|
|
51
56
|
runtime: worker?.runtime.adapter ?? adapter.name,
|
|
52
57
|
trustDomains: worker?.routing.trustDomains,
|
|
53
58
|
region: worker?.routing.regions?.[0],
|
|
@@ -64,23 +69,16 @@ export function workerCandidates(adapters, registered, snapshot) {
|
|
|
64
69
|
});
|
|
65
70
|
});
|
|
66
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Worker legality is intentionally narrow. Descriptive capability labels and provider
|
|
74
|
+
* quota are facts for decide(), not hard gates. An explicit runtime is retained as a
|
|
75
|
+
* compatibility/caller-owned constraint, and an explicitly offline worker is illegal.
|
|
76
|
+
*/
|
|
67
77
|
export function satisfiesWorker(candidate, requirements) {
|
|
68
|
-
if (candidate.availability
|
|
69
|
-
return false;
|
|
70
|
-
if (candidate.resourceHealthy === false)
|
|
71
|
-
return false;
|
|
72
|
-
if (!requirements.capabilities.every(capability => candidate.capabilities.includes(capability)))
|
|
78
|
+
if (candidate.availability === 'offline')
|
|
73
79
|
return false;
|
|
74
80
|
if (requirements.runtime && candidate.runtime !== requirements.runtime)
|
|
75
81
|
return false;
|
|
76
|
-
if (requirements.taskKind && candidate.taskKind !== requirements.taskKind)
|
|
77
|
-
return false;
|
|
78
|
-
if (requirements.trustDomain && !candidate.trustDomains?.includes(requirements.trustDomain))
|
|
79
|
-
return false;
|
|
80
|
-
if (requirements.region && candidate.region !== requirements.region)
|
|
81
|
-
return false;
|
|
82
|
-
if (requirements.labels && Object.entries(requirements.labels).some(([key, value]) => candidate.labels?.[key] !== value))
|
|
83
|
-
return false;
|
|
84
82
|
return true;
|
|
85
83
|
}
|
|
86
84
|
export function eligibleWorkerCandidates(candidates, requirements) {
|
|
@@ -88,8 +86,8 @@ export function eligibleWorkerCandidates(candidates, requirements) {
|
|
|
88
86
|
}
|
|
89
87
|
function deterministicWorker(eligible) {
|
|
90
88
|
return [...eligible].map((candidate, index) => ({ candidate, index })).sort((left, right) => {
|
|
91
|
-
const
|
|
92
|
-
return
|
|
89
|
+
const preference = (item) => item.adapter === 'chatgpt' ? 0 : 1;
|
|
90
|
+
return preference(left.candidate) - preference(right.candidate) || left.index - right.index;
|
|
93
91
|
})[0].candidate;
|
|
94
92
|
}
|
|
95
93
|
function selection(selected, selectedBy, decisionEvidence) {
|
|
@@ -113,30 +111,35 @@ function selection(selected, selectedBy, decisionEvidence) {
|
|
|
113
111
|
export function selectWorker(candidates, requirements) {
|
|
114
112
|
const eligible = eligibleWorkerCandidates(candidates, requirements);
|
|
115
113
|
if (eligible.length === 0)
|
|
116
|
-
throw new Error('No eligible worker satisfies the
|
|
114
|
+
throw new Error('No eligible worker satisfies the authoritative worker constraints');
|
|
117
115
|
const selected = deterministicWorker(eligible);
|
|
118
|
-
return { candidate: selected, selection: selection(selected, 'worker-router:
|
|
116
|
+
return { candidate: selected, selection: selection(selected, 'worker-router:fallback') };
|
|
119
117
|
}
|
|
120
|
-
/**
|
|
118
|
+
/** Gather factual worker/task/resource context, then let decide() choose among legal workers. */
|
|
121
119
|
export async function routeWorker(candidates, requirements, options = {}) {
|
|
122
120
|
const eligible = eligibleWorkerCandidates(candidates, requirements);
|
|
123
121
|
if (eligible.length === 0)
|
|
124
|
-
throw new Error('No eligible worker satisfies the
|
|
122
|
+
throw new Error('No eligible worker satisfies the authoritative worker constraints');
|
|
125
123
|
const deterministic = deterministicWorker(eligible);
|
|
126
124
|
if (eligible.length === 1) {
|
|
127
125
|
const evidence = { mode: options.decisionMode ?? 'off', fallback: true };
|
|
128
|
-
return { candidate: deterministic, selection: selection(deterministic, 'worker-router:
|
|
126
|
+
return { candidate: deterministic, selection: selection(deterministic, 'worker-router:constraint', evidence) };
|
|
129
127
|
}
|
|
128
|
+
const rules = await loadWorkerRouterRules(options.rulesPath);
|
|
130
129
|
const facts = JSON.parse(JSON.stringify({
|
|
131
130
|
task: options.taskFacts ?? {},
|
|
132
|
-
requirements,
|
|
131
|
+
explicit_constraints: { runtime: requirements.runtime ?? null },
|
|
132
|
+
routing_principles: DEFAULT_WORKER_ROUTER_PRINCIPLES,
|
|
133
|
+
environment_rules: rules.text,
|
|
134
|
+
usage_snapshot: options.usage ?? null,
|
|
133
135
|
candidates: eligible.map(item => ({
|
|
134
136
|
id: item.workerId,
|
|
135
137
|
adapter: item.adapter,
|
|
136
|
-
capabilities: [...item.capabilities],
|
|
137
138
|
runtime: item.runtime ?? null,
|
|
138
|
-
|
|
139
|
+
availability: item.availability ?? null,
|
|
140
|
+
declaredCapabilities: [...item.capabilities],
|
|
139
141
|
resourceProvider: item.resourceProvider ?? null,
|
|
142
|
+
resourceHealthy: item.resourceHealthy ?? null,
|
|
140
143
|
resourceUsedPercent: item.resourceUsedPercent ?? null,
|
|
141
144
|
resourceRemainingPercent: item.resourceRemainingPercent ?? null,
|
|
142
145
|
resourceResetAt: item.resourceResetAt ?? null,
|
|
@@ -144,8 +147,12 @@ export async function routeWorker(candidates, requirements, options = {}) {
|
|
|
144
147
|
resourceWindows: item.resourceWindows ?? null,
|
|
145
148
|
})),
|
|
146
149
|
}));
|
|
147
|
-
const choice = await chooseWithDecision(options.decisionEngine, options.decisionMode ?? 'off', { facts }, {
|
|
150
|
+
const choice = await chooseWithDecision(options.decisionEngine, options.decisionMode ?? 'off', { facts }, {
|
|
151
|
+
type: 'choice',
|
|
152
|
+
question: 'Choose the best execution worker for this task. Use the task description, current usage, routing principles, and environment rules. Prefer ChatGPT when both can do the work; choose Codex when native/local execution is necessary. Do not choose a provider or model here.',
|
|
153
|
+
choices: eligible.map(item => item.workerId),
|
|
154
|
+
}, () => deterministic.workerId);
|
|
148
155
|
const selected = eligible.find(item => item.workerId === choice.choice) ?? deterministic;
|
|
149
|
-
const selectedBy = choice.evidence.engine && !choice.evidence.fallback ? 'worker-router:laya' : 'worker-router:
|
|
156
|
+
const selectedBy = choice.evidence.engine && !choice.evidence.fallback ? 'worker-router:laya' : 'worker-router:fallback';
|
|
150
157
|
return { candidate: selected, selection: selection(selected, selectedBy, choice.evidence) };
|
|
151
158
|
}
|
package/package.json
CHANGED
|
@@ -68,8 +68,8 @@ Do not create separate Tasks merely for "analyze", "format", "call tool", "check
|
|
|
68
68
|
- Prefer independently verifiable Tasks with stable IDs, but do not split work solely to make Tasks smaller.
|
|
69
69
|
- A Task describes what an agent must accomplish; never emit a shell command as a worker Task.
|
|
70
70
|
- Use dependencies only when execution order actually matters.
|
|
71
|
-
-
|
|
72
|
-
- Do not choose
|
|
71
|
+
- Describe each child Task precisely enough for worker-router to decide from the Task itself. Do not invent Codex/ChatGPT capability labels. workerRequirements is optional and should normally be omitted; use an explicit runtime only when the objective already requires that runtime.
|
|
72
|
+
- Do not choose codex/chatgpt, provider/model, or usage probes.
|
|
73
73
|
- Every child Task must declare exactly one output: `task_pr` or `file`.
|
|
74
74
|
- Every child Task must include `storySize` (`S`, `M`, or `L`); use `M` when uncertain.
|
|
75
75
|
- Do not create bookkeeping, waiting, status-checking, wrapper, or planning Tasks. Your response itself is the planning round.
|
|
@@ -86,4 +86,4 @@ For `objective_status: "in_progress"`, `assessment` must be Markdown containing:
|
|
|
86
86
|
|
|
87
87
|
For `objective_status: "satisfied"`, `assessment` may be a concise evidence-based completion assessment without a graph.
|
|
88
88
|
|
|
89
|
-
Each item in
|
|
89
|
+
Each item in next_tasks contains id, input, output, and storySize. It may also contain priority, projectName, agentName, dependencies, capabilities, workerRequirements, maxAttempts, and timeoutMs. Adapter/routing fields are selected by Relay after planning; do not invent them.
|
|
@@ -54,13 +54,14 @@ Keep these concepts distinct: observation is not root cause; hypothesis is not r
|
|
|
54
54
|
|
|
55
55
|
Every new model-backed executable task follows this order:
|
|
56
56
|
|
|
57
|
-
1. The planner
|
|
58
|
-
2.
|
|
59
|
-
3.
|
|
60
|
-
4.
|
|
61
|
-
5.
|
|
57
|
+
1. The planner describes the executable Task precisely. It does not invent a capability matrix for Codex versus ChatGPT. workerRequirements is optional compatibility metadata; an explicit runtime may be used only when the caller already knows the Task must use that runtime.
|
|
58
|
+
2. worker-router gathers factual Task context, discovered worker availability, the current shared usage snapshot, built-in routing principles, and optional local free-text rules. Only authoritative legality facts such as an explicitly offline worker or an explicit caller-owned runtime constraint are hard gates. Descriptive capability labels, region/trust labels, and provider quota are decision facts rather than ordinary worker hard gates.
|
|
59
|
+
3. When more than one legal model-backed worker exists, worker-router calls the generic typed decide(request, contract) primitive to choose the execution worker. Its default principles prefer ChatGPT when both workers can execute the Task, prefer Codex when native/local execution is necessary, and treat Codex/OpenAI quota pressure as a preference rather than proof that the Codex worker is unusable.
|
|
60
|
+
4. model-router runs only after worker selection and independently chooses provider/model/profile for that worker. In particular, an exhausted OpenAI quota must not eliminate the Codex worker before Model Router has a chance to choose another Codex provider/profile.
|
|
61
|
+
5. decide() owns no routing facts or legality policy. Its optional Laya implementation is a transient CLI subprocess per decision; unavailable/invalid decisions fall back deterministically. src/usage.ts remains the shared resource-fact source.
|
|
62
|
+
6. Relay persists the selected worker and model routing on the durable task before launch.
|
|
62
63
|
|
|
63
|
-
Planner output must not hard-code
|
|
64
|
+
Planner output must not hard-code codex/chatgpt, provider preference, inferred worker capabilities, or usage probes. Worker Router and Model Router are separate responsibilities. Legacy task records that already contain adapter/routing/worker-requirement metadata remain readable.
|
|
64
65
|
|
|
65
66
|
## Story size
|
|
66
67
|
|
|
@@ -131,7 +132,7 @@ Job runtime status is derived, not persisted. Relay computes it from lifecycle p
|
|
|
131
132
|
|
|
132
133
|
A normal task never merges a PR. After all non-superseded work gates pass, Relay creates a SHA-bound final review task. The reviewer emits exactly one of `review.approved`, `review.changes_required`, or `review.blocked`. When `autoMerge` is enabled (default), Relay merges only after `review.approved`, pinned to the exact reviewed head SHA. A new task or new PR head makes earlier final-review evidence stale and requires a fresh review.
|
|
133
134
|
|
|
134
|
-
Final-review routing follows the same worker-selection boundary as executable work.
|
|
135
|
+
Final-review routing follows the same factual worker-selection boundary as executable work. Explicitly offline workers and explicit reviewer runtime constraints are hard gates; provider quota and descriptive capability labels do not by themselves make a worker illegal. Among eligible workers, Relay prefers a reviewer with a different worker identity from the implementation tasks; when that is unavailable it prefers a different provider/model, then falls back to the first eligible worker. The selected worker, selectedBy reason, and reviewerRouting event data are durable evidence. No provider is a universal reviewer default.
|
|
135
136
|
|
|
136
137
|
## Job, Task, and planner ownership
|
|
137
138
|
|