@compilr-dev/sdk 0.10.19 → 0.10.21
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 +2 -2
- package/dist/index.js +1 -1
- package/dist/team/consult-tool.d.ts +103 -0
- package/dist/team/consult-tool.js +142 -0
- package/dist/team/index.d.ts +2 -0
- package/dist/team/index.js +3 -0
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
*/
|
|
36
36
|
export { createCompilrAgent } from './agent.js';
|
|
37
37
|
export type { CompilrAgentConfig, CompilrAgent, RunOptions, RunResult, ToolCallRecord, ToolConfig, UsageInfo, ProviderType, PermissionCallback, GuardrailConfig, ContextConfig, CapabilitiesConfig, } from './config.js';
|
|
38
|
-
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
38
|
+
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, createConsultTool, buildConsultQuestionMessage, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
39
39
|
export type { AgentTeamConfig, TeamAgentConfig, ITeamPersistence, IArtifactStorage, ISessionRegistry, CustomAgentDefinition, AgentTemplate, AgentWorkshopData, WorkshopRoleDef, WorkshopToolProfile, WorkshopModelTier, WorkshopSkillDef, PlanSubmitInfo, PlanSubmitResult, PlanModeExitInfo, PlanModeCallbacks, ToolConfig as TeamToolConfig, ToolTier, ToolGroup, ProfileInfo, } from './team/index.js';
|
|
40
|
-
export type { AgentRole, RoleMetadata, ToolProfile, MascotExpression, BackgroundSessionInfo, SerializedTeam, SerializedTeamAgent, TeamMetadata, TeamEvent, TeamEventType, TeamEventHandler, Artifact, ArtifactType as TeamArtifactType, ArtifactSummary as TeamArtifactSummary, CreateArtifactOptions, UpdateArtifactOptions, SerializedArtifact, SharedContext, SharedProjectInfo, SharedTeamInfo, TeamRosterEntry, TeamActivity, TeamActivityType, SharedDecision, TokenBudget, SerializedSharedContext, ParsedMention, ParsedInput, ResolvedMention, ResolveOptions, ResolutionSource, Delegation, DelegationStatus, DelegationResult, CompletionEvent, CreateDelegationOptions, DelegationStats, DelegationTrackerEvents, HandoffResult, HandoffToolConfig, HandoffIntent, HandoffValidationResult, NormalizedRole, SkillToolRequirement, } from './team/index.js';
|
|
40
|
+
export type { AgentRole, RoleMetadata, ToolProfile, MascotExpression, BackgroundSessionInfo, SerializedTeam, SerializedTeamAgent, TeamMetadata, TeamEvent, TeamEventType, TeamEventHandler, Artifact, ArtifactType as TeamArtifactType, ArtifactSummary as TeamArtifactSummary, CreateArtifactOptions, UpdateArtifactOptions, SerializedArtifact, SharedContext, SharedProjectInfo, SharedTeamInfo, TeamRosterEntry, TeamActivity, TeamActivityType, SharedDecision, TokenBudget, SerializedSharedContext, ParsedMention, ParsedInput, ResolvedMention, ResolveOptions, ResolutionSource, Delegation, DelegationStatus, DelegationResult, CompletionEvent, CreateDelegationOptions, DelegationStats, DelegationTrackerEvents, HandoffResult, HandoffToolConfig, HandoffIntent, HandoffValidationResult, ConsultInput, ConsultResult, ConsultToolConfig, NormalizedRole, SkillToolRequirement, } from './team/index.js';
|
|
41
41
|
export { ROLE_METADATA, ROLE_EXPERTISE, ROLE_GROUPS, PREDEFINED_ROLE_IDS, TOOL_GROUPS, TOOL_PROFILES, PROFILE_INFO, SKILL_REQUIREMENTS, CUSTOM_MASCOTS, buildAgentWorkshopData, buildSuggestedRolesMap, PLAN_MODE_BLOCKED_TOOLS, PLAN_MODE_DENIAL_MESSAGE, PLAN_MODE_PROMPT, isToolAllowedInPlanMode, getPlanModePrompt, } from './team/index.js';
|
|
42
42
|
export { getToolsForProfile, detectProfileFromTools, isProfileReadOnly, generateToolAwarenessPrompt, generateCoordinatorGuidance, generateSpecialistGuidance, createDefaultToolConfig, validateToolConfig, getAllGroupIds, getGroupInfo, getGroupsByTier, getGroupsForProfile, assignMascot, generateCustomAgentSystemPrompt, getCustomAgentToolFilter, getCustomAgentProfileLabel, validateAgentId, isAgentIdTaken, createCustomAgentDefinition, listTemplates, getTemplate, saveTemplate, updateTemplate, deleteTemplate, createAgentFromTemplate, parseInputForMentions, getReferencedAgents, hasReferences, buildMessageWithContext, buildContextMap, findAgentForRole, findAgentById, getAvailableSpecialists, getSpecialistsSummary, hasSpecialists, suggestOwner, suggestOwners, matchesAgentExpertise, wouldCreateLoop, recordAssignment, getAssignmentHistory, clearAssignmentHistory, clearAllAssignmentHistory, canReassign, resolveAgentIdCollision, setActiveSharedContext, getActiveSharedContext, recordTeamActivity, getDefinedSkillNames, getSkillRequirements, checkSkillCompatibility, getCompatibleSkills, getAllRequiredTools, getSkillsByCategory, } from './team/index.js';
|
|
43
43
|
export { codingPreset, readOnlyPreset, resolvePreset } from './presets/index.js';
|
package/dist/index.js
CHANGED
|
@@ -41,7 +41,7 @@ export { createCompilrAgent } from './agent.js';
|
|
|
41
41
|
// Multi-Agent Team Orchestration
|
|
42
42
|
// =============================================================================
|
|
43
43
|
// Core classes
|
|
44
|
-
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
44
|
+
export { AgentTeam, TeamAgent, SharedContextManager, ArtifactStore, DelegationTracker, ContextResolver, createDelegationStatusTool, createHandoffTool, buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, createConsultTool, buildConsultQuestionMessage, ROLE_NAME_ALIASES, normalizeRoleName, } from './team/index.js';
|
|
45
45
|
// Constants
|
|
46
46
|
export { ROLE_METADATA, ROLE_EXPERTISE, ROLE_GROUPS, PREDEFINED_ROLE_IDS, TOOL_GROUPS, TOOL_PROFILES, PROFILE_INFO, SKILL_REQUIREMENTS, CUSTOM_MASCOTS, buildAgentWorkshopData, buildSuggestedRolesMap,
|
|
47
47
|
// Plan mode
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consult Tool — Specialist-to-Specialist Sync Borrow
|
|
3
|
+
*
|
|
4
|
+
* Fills the gap in the multi-agent tool set where a specialist needs a
|
|
5
|
+
* focused answer from another specialist without giving up the conversation.
|
|
6
|
+
*
|
|
7
|
+
* Symmetric tool set:
|
|
8
|
+
*
|
|
9
|
+
* | Caller | Sync | Async | Transfer |
|
|
10
|
+
* |--------------|--------------|------------------------|-----------|
|
|
11
|
+
* | Coordinator | `delegate` | `delegate_background` | — |
|
|
12
|
+
* | Specialist | `consult` | (deferred) | `handoff` |
|
|
13
|
+
*
|
|
14
|
+
* Loop-impossible by construction: the borrower blocks waiting for the
|
|
15
|
+
* target's response and never yields control. No chain state, no hop
|
|
16
|
+
* counter, no one-hop rule needed. Each agent's run is bounded by its
|
|
17
|
+
* existing max-iterations cap, and the call stack unwinds naturally if
|
|
18
|
+
* the target itself consults a third agent.
|
|
19
|
+
*
|
|
20
|
+
* Spec:
|
|
21
|
+
* /workspace/project-docs/00-requirements/compilr-dev-sdk/consult-tool-spec.md
|
|
22
|
+
*/
|
|
23
|
+
import { type Tool } from '@compilr-dev/agents';
|
|
24
|
+
import type { AgentTeam } from './team.js';
|
|
25
|
+
export interface ConsultInput {
|
|
26
|
+
agentId: string;
|
|
27
|
+
question: string;
|
|
28
|
+
context?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result the platform's `onConsult` handler hands back to the tool.
|
|
32
|
+
* Identical shape to what the LLM sees, with an optional error path.
|
|
33
|
+
*/
|
|
34
|
+
export interface ConsultResult {
|
|
35
|
+
/** Final response text from the target agent. */
|
|
36
|
+
answer: string;
|
|
37
|
+
/** Target agent ID (echoed back for the LLM's benefit). */
|
|
38
|
+
agentId: string;
|
|
39
|
+
/** Error message if the consult failed at the platform layer
|
|
40
|
+
* (target run exceeded max iterations, transport error, etc.). */
|
|
41
|
+
error?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for `createConsultTool`.
|
|
45
|
+
*
|
|
46
|
+
* `onConsult` is intentionally platform-shaped — each host runs sub-agents
|
|
47
|
+
* differently (CLI's REPL sub-context, Desktop's agent-manager, in-process
|
|
48
|
+
* Agent.run). The SDK owns validation and message format; the platform
|
|
49
|
+
* owns the actual run.
|
|
50
|
+
*/
|
|
51
|
+
export interface ConsultToolConfig {
|
|
52
|
+
/** The team instance — used to validate target agent membership. */
|
|
53
|
+
team: AgentTeam;
|
|
54
|
+
/** The borrowing agent's ID. */
|
|
55
|
+
currentAgentId: string;
|
|
56
|
+
/**
|
|
57
|
+
* Platform-specific consult handler. Called after validation passes.
|
|
58
|
+
* Should:
|
|
59
|
+
* 1. Synthesise the question message (use `buildConsultQuestionMessage`).
|
|
60
|
+
* 2. Run the target agent against that message (sub-run, not a turn
|
|
61
|
+
* in the borrower's conversation).
|
|
62
|
+
* 3. Return the target's final response text.
|
|
63
|
+
*
|
|
64
|
+
* The target's conversation history is NOT mutated by a consult — the
|
|
65
|
+
* call is transient.
|
|
66
|
+
*/
|
|
67
|
+
onConsult: (targetAgentId: string, question: string, context: string | undefined) => Promise<{
|
|
68
|
+
answer: string;
|
|
69
|
+
error?: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build the synthesised message handed to the target agent. The
|
|
74
|
+
* `[Consult from $X]` marker keeps the target oriented and gives future
|
|
75
|
+
* tooling a way to distinguish consult sub-runs from direct user input or
|
|
76
|
+
* handoff-injected turns.
|
|
77
|
+
*
|
|
78
|
+
* Format:
|
|
79
|
+
*
|
|
80
|
+
* [Consult from $arch]
|
|
81
|
+
*
|
|
82
|
+
* Question: <verbatim question>
|
|
83
|
+
*
|
|
84
|
+
* Context:
|
|
85
|
+
* <verbatim context> (whole block omitted when absent)
|
|
86
|
+
*/
|
|
87
|
+
export declare function buildConsultQuestionMessage(input: {
|
|
88
|
+
sourceAgentId: string;
|
|
89
|
+
question: string;
|
|
90
|
+
context?: string;
|
|
91
|
+
}): string;
|
|
92
|
+
/**
|
|
93
|
+
* Create a `consult` tool bound to a specific borrowing agent.
|
|
94
|
+
*
|
|
95
|
+
* Validation rules (enforced before `onConsult` fires):
|
|
96
|
+
* 1. `agentId` and `question` are non-empty strings.
|
|
97
|
+
* 2. Target agent exists in the team.
|
|
98
|
+
* 3. Target is not the borrower itself.
|
|
99
|
+
* 4. Target is not `default` — specialists escalate to the coordinator
|
|
100
|
+
* via `handoff`, not `consult`. (Coordinators have `delegate` for the
|
|
101
|
+
* same semantic in the other direction.)
|
|
102
|
+
*/
|
|
103
|
+
export declare function createConsultTool(config: ConsultToolConfig): Tool<ConsultInput>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consult Tool — Specialist-to-Specialist Sync Borrow
|
|
3
|
+
*
|
|
4
|
+
* Fills the gap in the multi-agent tool set where a specialist needs a
|
|
5
|
+
* focused answer from another specialist without giving up the conversation.
|
|
6
|
+
*
|
|
7
|
+
* Symmetric tool set:
|
|
8
|
+
*
|
|
9
|
+
* | Caller | Sync | Async | Transfer |
|
|
10
|
+
* |--------------|--------------|------------------------|-----------|
|
|
11
|
+
* | Coordinator | `delegate` | `delegate_background` | — |
|
|
12
|
+
* | Specialist | `consult` | (deferred) | `handoff` |
|
|
13
|
+
*
|
|
14
|
+
* Loop-impossible by construction: the borrower blocks waiting for the
|
|
15
|
+
* target's response and never yields control. No chain state, no hop
|
|
16
|
+
* counter, no one-hop rule needed. Each agent's run is bounded by its
|
|
17
|
+
* existing max-iterations cap, and the call stack unwinds naturally if
|
|
18
|
+
* the target itself consults a third agent.
|
|
19
|
+
*
|
|
20
|
+
* Spec:
|
|
21
|
+
* /workspace/project-docs/00-requirements/compilr-dev-sdk/consult-tool-spec.md
|
|
22
|
+
*/
|
|
23
|
+
import { defineTool } from '@compilr-dev/agents';
|
|
24
|
+
// =============================================================================
|
|
25
|
+
// Canonical question-message format
|
|
26
|
+
// =============================================================================
|
|
27
|
+
/**
|
|
28
|
+
* Build the synthesised message handed to the target agent. The
|
|
29
|
+
* `[Consult from $X]` marker keeps the target oriented and gives future
|
|
30
|
+
* tooling a way to distinguish consult sub-runs from direct user input or
|
|
31
|
+
* handoff-injected turns.
|
|
32
|
+
*
|
|
33
|
+
* Format:
|
|
34
|
+
*
|
|
35
|
+
* [Consult from $arch]
|
|
36
|
+
*
|
|
37
|
+
* Question: <verbatim question>
|
|
38
|
+
*
|
|
39
|
+
* Context:
|
|
40
|
+
* <verbatim context> (whole block omitted when absent)
|
|
41
|
+
*/
|
|
42
|
+
export function buildConsultQuestionMessage(input) {
|
|
43
|
+
const header = `[Consult from $${input.sourceAgentId}]`;
|
|
44
|
+
const questionBlock = `Question: ${input.question}`;
|
|
45
|
+
if (input.context && input.context.trim().length > 0) {
|
|
46
|
+
return `${header}\n\n${questionBlock}\n\nContext:\n${input.context}`;
|
|
47
|
+
}
|
|
48
|
+
return `${header}\n\n${questionBlock}`;
|
|
49
|
+
}
|
|
50
|
+
// =============================================================================
|
|
51
|
+
// Tool factory
|
|
52
|
+
// =============================================================================
|
|
53
|
+
/**
|
|
54
|
+
* Create a `consult` tool bound to a specific borrowing agent.
|
|
55
|
+
*
|
|
56
|
+
* Validation rules (enforced before `onConsult` fires):
|
|
57
|
+
* 1. `agentId` and `question` are non-empty strings.
|
|
58
|
+
* 2. Target agent exists in the team.
|
|
59
|
+
* 3. Target is not the borrower itself.
|
|
60
|
+
* 4. Target is not `default` — specialists escalate to the coordinator
|
|
61
|
+
* via `handoff`, not `consult`. (Coordinators have `delegate` for the
|
|
62
|
+
* same semantic in the other direction.)
|
|
63
|
+
*/
|
|
64
|
+
export function createConsultTool(config) {
|
|
65
|
+
const { team, currentAgentId, onConsult } = config;
|
|
66
|
+
return defineTool({
|
|
67
|
+
name: 'consult',
|
|
68
|
+
description: 'Ask another specialist a focused question and continue the conversation yourself. ' +
|
|
69
|
+
'Use this when you need a quick opinion or expertise input from a teammate without giving up the conversation. ' +
|
|
70
|
+
'Unlike handoff, you keep ownership — the target answers and control returns to you. ' +
|
|
71
|
+
'Example: $arch can consult $pm on scope, get an answer, and continue designing.',
|
|
72
|
+
inputSchema: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
agentId: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
description: 'Target specialist agent ID to consult (e.g., "pm", "qa", "dev"). ' +
|
|
78
|
+
'Cannot be yourself or "default" (use handoff to escalate to the coordinator).',
|
|
79
|
+
},
|
|
80
|
+
question: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
description: 'The focused question you want answered — be specific.',
|
|
83
|
+
},
|
|
84
|
+
context: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'Optional supporting material the target needs to answer well ' +
|
|
87
|
+
'(code snippet, design constraint, current state, etc.).',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
required: ['agentId', 'question'],
|
|
91
|
+
},
|
|
92
|
+
execute: async (input) => {
|
|
93
|
+
// LLM-supplied JSON may not match the typed schema — validate as if
|
|
94
|
+
// every field could be missing or whitespace. Matches the handoff
|
|
95
|
+
// tool's defensive style.
|
|
96
|
+
if (!input.agentId || input.agentId.trim().length === 0) {
|
|
97
|
+
return { success: false, error: 'agentId is required' };
|
|
98
|
+
}
|
|
99
|
+
if (!input.question || input.question.trim().length === 0) {
|
|
100
|
+
return { success: false, error: 'question is required and cannot be empty' };
|
|
101
|
+
}
|
|
102
|
+
const targetId = input.agentId.trim();
|
|
103
|
+
const question = input.question.trim();
|
|
104
|
+
const context = input.context?.trim() ?? undefined;
|
|
105
|
+
if (targetId === currentAgentId) {
|
|
106
|
+
return { success: false, error: 'Cannot consult yourself.' };
|
|
107
|
+
}
|
|
108
|
+
if (targetId === 'default') {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: 'Cannot consult $default. To escalate to the coordinator, use `handoff` instead. ' +
|
|
112
|
+
'`consult` is for specialist-to-specialist questions only.',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (!team.has(targetId)) {
|
|
116
|
+
const available = team
|
|
117
|
+
.getAll()
|
|
118
|
+
.map((a) => a.id)
|
|
119
|
+
.filter((id) => id !== 'default' && id !== currentAgentId)
|
|
120
|
+
.join(', ');
|
|
121
|
+
return {
|
|
122
|
+
success: false,
|
|
123
|
+
error: `Agent "${targetId}" not found in team. Available specialists: ${available || '(none)'}`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const { answer, error } = await onConsult(targetId, question, context);
|
|
128
|
+
if (error) {
|
|
129
|
+
return { success: false, error };
|
|
130
|
+
}
|
|
131
|
+
const result = { answer, agentId: targetId };
|
|
132
|
+
return { success: true, result };
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
return {
|
|
136
|
+
success: false,
|
|
137
|
+
error: `Consult failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
package/dist/team/index.d.ts
CHANGED
|
@@ -42,5 +42,7 @@ export { createDelegationStatusTool, createHandoffTool } from './delegation-tool
|
|
|
42
42
|
export type { HandoffResult, HandoffToolConfig } from './delegation-tools.js';
|
|
43
43
|
export { buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, } from './handoff-orchestration.js';
|
|
44
44
|
export type { HandoffIntent, HandoffValidationResult } from './handoff-orchestration.js';
|
|
45
|
+
export { createConsultTool, buildConsultQuestionMessage } from './consult-tool.js';
|
|
46
|
+
export type { ConsultInput, ConsultResult, ConsultToolConfig } from './consult-tool.js';
|
|
45
47
|
export { ROLE_NAME_ALIASES, normalizeRoleName } from './role-aliases.js';
|
|
46
48
|
export type { NormalizedRole } from './role-aliases.js';
|
package/dist/team/index.js
CHANGED
|
@@ -36,6 +36,9 @@ export { createDelegationStatusTool, createHandoffTool } from './delegation-tool
|
|
|
36
36
|
// Handoff orchestration helpers — shared between CLI and Desktop for the
|
|
37
37
|
// post-turn stash/dispatch pattern. See handoff-orchestration.ts header.
|
|
38
38
|
export { buildHandoffTaskMessage, validateHandoffIntent, HandoffStash, } from './handoff-orchestration.js';
|
|
39
|
+
// Consult tool — specialist-to-specialist sync borrow. See consult-tool.ts
|
|
40
|
+
// header. Spec: project-docs/00-requirements/compilr-dev-sdk/consult-tool-spec.md
|
|
41
|
+
export { createConsultTool, buildConsultQuestionMessage } from './consult-tool.js';
|
|
39
42
|
// Role-name aliases — longform → canonical AgentRole short key. Shared
|
|
40
43
|
// between CLI and Desktop for `suggestedAgents` translation when batch-
|
|
41
44
|
// adding a project type's default team. See role-aliases.ts header.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.21",
|
|
4
4
|
"description": "Universal agent runtime for building AI-powered applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./team/role-aliases": {
|
|
14
|
+
"types": "./dist/team/role-aliases.d.ts",
|
|
15
|
+
"import": "./dist/team/role-aliases.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"files": [
|