@lov3kaizen/agentsea-crews 1.0.0 → 1.1.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.
@@ -1428,7 +1428,80 @@ var AgentCapabilities = class {
1428
1428
  }
1429
1429
  };
1430
1430
 
1431
+ // src/agents/CoreExecutor.ts
1432
+ async function loadProvider(providerName) {
1433
+ const ctorName = resolveProviderCtorName(providerName);
1434
+ let core;
1435
+ try {
1436
+ core = await import("@lov3kaizen/agentsea-core");
1437
+ } catch {
1438
+ throw new Error(
1439
+ 'CrewAgent requires "@lov3kaizen/agentsea-core" to execute against a real LLM. Install it, or pass a custom `execute` function (or `mock: true`) to createCrewAgent / createCrew.'
1440
+ );
1441
+ }
1442
+ const Ctor = core[ctorName];
1443
+ return new Ctor();
1444
+ }
1445
+ function resolveProviderCtorName(providerName) {
1446
+ switch ((providerName ?? "").toLowerCase()) {
1447
+ case "anthropic":
1448
+ case "claude":
1449
+ return "AnthropicProvider";
1450
+ case "openai":
1451
+ case "gpt":
1452
+ return "OpenAIProvider";
1453
+ case "gemini":
1454
+ case "google":
1455
+ return "GeminiProvider";
1456
+ case "ollama":
1457
+ return "OllamaProvider";
1458
+ default:
1459
+ throw new Error(
1460
+ `CrewAgent: unsupported provider "${providerName}". Supported providers are: anthropic, openai, gemini, ollama. Pass a custom \`execute\` function to createCrewAgent for any other provider.`
1461
+ );
1462
+ }
1463
+ }
1464
+ function createCoreExecutor(config, options = {}) {
1465
+ let providerPromise;
1466
+ const getProvider = () => {
1467
+ if (!providerPromise) {
1468
+ providerPromise = options.provider ? Promise.resolve(options.provider) : loadProvider(config.provider);
1469
+ }
1470
+ return providerPromise;
1471
+ };
1472
+ return async (input, systemPrompt) => {
1473
+ const provider = await getProvider();
1474
+ const start = Date.now();
1475
+ const response = await provider.generateResponse(
1476
+ [{ role: "user", content: input }],
1477
+ {
1478
+ model: config.model,
1479
+ systemPrompt,
1480
+ temperature: config.temperature,
1481
+ maxTokens: config.maxTokens
1482
+ }
1483
+ );
1484
+ return {
1485
+ output: response.content,
1486
+ tokensUsed: response.usage.inputTokens + response.usage.outputTokens,
1487
+ latencyMs: Date.now() - start,
1488
+ iterations: 1
1489
+ };
1490
+ };
1491
+ }
1492
+
1431
1493
  // src/agents/CrewAgent.ts
1494
+ function modelCostWeight(model) {
1495
+ const m = (model ?? "").toLowerCase();
1496
+ if (m.includes("opus") || m.includes("gpt-5") || m.includes("o3")) return 5;
1497
+ if (m.includes("sonnet") || m.includes("gpt-4.1") || m.includes("gpt-4") && !m.includes("mini") || m.includes("gemini-1.5-pro") || m.includes("gemini-2.5-pro")) {
1498
+ return 3;
1499
+ }
1500
+ if (m.includes("haiku") || m.includes("mini") || m.includes("flash") || m.includes("llama") || m.includes("mistral")) {
1501
+ return 1;
1502
+ }
1503
+ return 3;
1504
+ }
1432
1505
  var CrewAgent = class _CrewAgent {
1433
1506
  id;
1434
1507
  name;
@@ -1467,10 +1540,11 @@ var CrewAgent = class _CrewAgent {
1467
1540
  */
1468
1541
  async execute(input) {
1469
1542
  if (!this.executeFunc) {
1543
+ const tokensUsed = 100 + Math.min(input.length, 400);
1470
1544
  const mockResult = {
1471
1545
  output: `[Mock response from ${this.name}]: ${input.slice(0, 100)}...`,
1472
- tokensUsed: Math.floor(Math.random() * 500) + 100,
1473
- latencyMs: Math.floor(Math.random() * 2e3) + 500,
1546
+ tokensUsed,
1547
+ latencyMs: 0,
1474
1548
  iterations: 1
1475
1549
  };
1476
1550
  this.totalTokensUsed += mockResult.tokensUsed;
@@ -1573,16 +1647,27 @@ ${JSON.stringify(task.context, null, 2)}`);
1573
1647
  ) ?? true
1574
1648
  ).map((c) => c.name);
1575
1649
  const estimatedTime = this.estimateTaskTime(task);
1650
+ const estimatedCost = this.estimateTaskCost(estimatedTime);
1576
1651
  const reasoning = this.generateBidReasoning(task, confidence, matchedCaps);
1577
1652
  return Promise.resolve({
1578
1653
  agentName: this.name,
1579
1654
  taskId: task.id ?? "unknown",
1580
1655
  confidence,
1581
1656
  estimatedTime,
1657
+ estimatedCost,
1582
1658
  reasoning,
1583
1659
  capabilities: matchedCaps
1584
1660
  });
1585
1661
  }
1662
+ /**
1663
+ * Estimate a relative cost for handling a task. Combines the agent's model
1664
+ * price tier with the estimated effort so the auction `cheapest` criterion
1665
+ * can distinguish a cheap-but-slower model from an expensive-but-faster one.
1666
+ * The unit is arbitrary and only meaningful relative to other bids.
1667
+ */
1668
+ estimateTaskCost(estimatedTime) {
1669
+ return modelCostWeight(this.model) * Math.max(estimatedTime, 1);
1670
+ }
1586
1671
  /**
1587
1672
  * Check if agent has all required capabilities
1588
1673
  */
@@ -1768,7 +1853,13 @@ Please provide helpful guidance based on your expertise.
1768
1853
  }
1769
1854
  };
1770
1855
  function createCrewAgent(options) {
1771
- return new CrewAgent(options);
1856
+ if (options.execute || options.mock) {
1857
+ return new CrewAgent(options);
1858
+ }
1859
+ return new CrewAgent({
1860
+ ...options,
1861
+ execute: createCoreExecutor(options.config, { provider: options.provider })
1862
+ });
1772
1863
  }
1773
1864
 
1774
1865
  // src/agents/AgentRegistry.ts
@@ -2468,9 +2559,9 @@ var AuctionStrategy = class extends BaseDelegationStrategy {
2468
2559
  }, bids[0]);
2469
2560
  case "cheapest":
2470
2561
  return bids.reduce((best, bid) => {
2471
- const bestTime = best.estimatedTime ?? Infinity;
2472
- const bidTime = bid.estimatedTime ?? Infinity;
2473
- return bidTime < bestTime ? bid : best;
2562
+ const bestCost = best.estimatedCost ?? best.estimatedTime ?? Infinity;
2563
+ const bidCost = bid.estimatedCost ?? bid.estimatedTime ?? Infinity;
2564
+ return bidCost < bestCost ? bid : best;
2474
2565
  }, bids[0]);
2475
2566
  case "confidence":
2476
2567
  default:
@@ -2953,9 +3044,8 @@ var ConsensusStrategy = class extends BaseDelegationStrategy {
2953
3044
  */
2954
3045
  async collectVotes(task, voters, candidates) {
2955
3046
  const votes = [];
2956
- const candidateNames = candidates.map((c) => c.name);
2957
3047
  for (const voter of voters) {
2958
- const vote = await this.getVote(voter, task, candidateNames);
3048
+ const vote = await this.getVote(voter, task, candidates);
2959
3049
  if (vote) {
2960
3050
  votes.push(vote);
2961
3051
  }
@@ -2963,33 +3053,35 @@ var ConsensusStrategy = class extends BaseDelegationStrategy {
2963
3053
  return votes;
2964
3054
  }
2965
3055
  /**
2966
- * Get a vote from an agent
3056
+ * Get a vote from an agent.
3057
+ *
3058
+ * Each voter ranks the candidates by how well their capabilities fit the
3059
+ * task (the same `calculateTaskScore` signal the BestMatch/Auction strategies
3060
+ * use), plus a small self-preference bias so an agent leans toward itself when
3061
+ * candidates are otherwise comparable. This is fully deterministic — given the
3062
+ * same agents and task it always produces the same votes — and explainable,
3063
+ * which is what consensus needs. (A future enhancement could replace this with
3064
+ * an actual LLM deliberation per voter; the tally/agreement logic is unchanged.)
2967
3065
  */
2968
3066
  getVote(voter, task, candidates) {
2969
- const scores = [];
2970
- for (const candidateName of candidates) {
2971
- if (candidateName === voter.name) {
2972
- scores.push({ name: candidateName, score: 0.7 });
2973
- } else {
2974
- const randomFactor = 0.8 + Math.random() * 0.4;
2975
- scores.push({
2976
- name: candidateName,
2977
- score: Math.random() * randomFactor
2978
- });
3067
+ if (candidates.length === 0) return Promise.resolve(null);
3068
+ const SELF_PREFERENCE_BONUS = 0.15;
3069
+ const scores = candidates.map((candidate) => {
3070
+ let score = candidate.calculateTaskScore(task);
3071
+ if (candidate.name === voter.name) {
3072
+ score += SELF_PREFERENCE_BONUS;
2979
3073
  }
2980
- }
2981
- scores.sort((a, b) => b.score - a.score);
3074
+ return { name: candidate.name, score };
3075
+ });
3076
+ scores.sort((a, b) => b.score - a.score || a.name.localeCompare(b.name));
2982
3077
  const selected = scores[0];
2983
3078
  if (!selected) return Promise.resolve(null);
2984
- let weight = 1;
2985
- if (this.weightedVoting) {
2986
- weight = voter.calculateTaskScore(task) || 0.5;
2987
- }
3079
+ const weight = this.weightedVoting ? voter.calculateTaskScore(task) || 0.5 : 1;
2988
3080
  return Promise.resolve({
2989
3081
  voter: voter.name,
2990
3082
  candidate: selected.name,
2991
3083
  weight,
2992
- reasoning: `Selected based on perceived suitability (score: ${selected.score.toFixed(2)})`
3084
+ reasoning: `Ranked "${selected.name}" highest by capability fit for the task (score: ${selected.score.toFixed(2)})`
2993
3085
  });
2994
3086
  }
2995
3087
  /**
@@ -3853,13 +3945,24 @@ var ConflictResolver = class {
3853
3945
  resolved: /* @__PURE__ */ new Date()
3854
3946
  };
3855
3947
  }
3948
+ /**
3949
+ * Normalize response content for equality comparison: trim, collapse runs of
3950
+ * whitespace, and lowercase. This groups textually-equivalent answers (ignoring
3951
+ * incidental formatting) over their FULL content rather than a fragile first-N
3952
+ * characters prefix. Note: this is exact-match-after-normalization, not semantic
3953
+ * similarity — agents that express the same idea with different wording will not
3954
+ * group. Semantic grouping would require embeddings (future enhancement).
3955
+ */
3956
+ normalizeContent(content) {
3957
+ return content.trim().replace(/\s+/g, " ").toLowerCase();
3958
+ }
3856
3959
  /**
3857
3960
  * Resolve by voting
3858
3961
  */
3859
3962
  resolveByVoting(conflict, _context) {
3860
3963
  const votes = /* @__PURE__ */ new Map();
3861
3964
  for (const response of conflict.responses) {
3862
- const key = response.content.substring(0, 100);
3965
+ const key = this.normalizeContent(response.content);
3863
3966
  const current = votes.get(key) ?? 0;
3864
3967
  votes.set(key, current + response.confidence);
3865
3968
  }
@@ -3872,7 +3975,7 @@ var ConflictResolver = class {
3872
3975
  }
3873
3976
  }
3874
3977
  const winner = conflict.responses.find(
3875
- (r) => r.content.substring(0, 100) === winningKey
3978
+ (r) => this.normalizeContent(r.content) === winningKey
3876
3979
  );
3877
3980
  return Promise.resolve({
3878
3981
  conflictId: conflict.id,
@@ -3888,7 +3991,31 @@ var ConflictResolver = class {
3888
3991
  * Resolve by authority
3889
3992
  */
3890
3993
  resolveByAuthority(conflict, _context) {
3891
- return Promise.resolve(this.resolveByConfidence(conflict));
3994
+ const ranked = conflict.responses.map((r) => ({
3995
+ response: r,
3996
+ authority: typeof r.metadata?.authority === "number" ? r.metadata.authority : void 0
3997
+ })).filter(
3998
+ (x) => x.authority !== void 0
3999
+ );
4000
+ if (ranked.length === 0) {
4001
+ return Promise.resolve({
4002
+ ...this.resolveByConfidence(conflict),
4003
+ strategy: "authority",
4004
+ explanation: "No authority metadata provided; fell back to highest confidence"
4005
+ });
4006
+ }
4007
+ const winnerEntry = ranked.reduce(
4008
+ (best, cur) => cur.authority > best.authority ? cur : best
4009
+ );
4010
+ return Promise.resolve({
4011
+ conflictId: conflict.id,
4012
+ strategy: "authority",
4013
+ winner: winnerEntry.response,
4014
+ explanation: `Selected response from highest-authority agent "${winnerEntry.response.agentName}" (authority: ${winnerEntry.authority})`,
4015
+ successful: true,
4016
+ escalated: false,
4017
+ resolved: /* @__PURE__ */ new Date()
4018
+ });
3892
4019
  }
3893
4020
  /**
3894
4021
  * Resolve by consensus
@@ -3896,7 +4023,7 @@ var ConflictResolver = class {
3896
4023
  resolveByConsensus(conflict, _context) {
3897
4024
  const contentGroups = /* @__PURE__ */ new Map();
3898
4025
  for (const response of conflict.responses) {
3899
- const key = response.content.substring(0, 100);
4026
+ const key = this.normalizeContent(response.content);
3900
4027
  const group = contentGroups.get(key) ?? [];
3901
4028
  group.push(response);
3902
4029
  contentGroups.set(key, group);
@@ -4056,7 +4183,12 @@ var Crew = class {
4056
4183
  */
4057
4184
  initializeAgents() {
4058
4185
  for (const agentConfig of this.config.agents) {
4059
- const agent = createCrewAgent({ config: agentConfig });
4186
+ const agent = createCrewAgent({
4187
+ config: agentConfig,
4188
+ execute: this.config.execute,
4189
+ mock: this.config.mock,
4190
+ provider: this.config.provider
4191
+ });
4060
4192
  this.addAgent(agent);
4061
4193
  }
4062
4194
  }
@@ -4704,7 +4836,7 @@ function createResearchCrewConfig(options = {}) {
4704
4836
  {
4705
4837
  name: "researcher",
4706
4838
  role: researcherRole,
4707
- model: options.model ?? "claude-sonnet-4-20250514",
4839
+ model: options.model ?? "claude-opus-4-8",
4708
4840
  provider: options.provider ?? "anthropic",
4709
4841
  tools: ["web-search", "read-document", ...options.tools ?? []],
4710
4842
  temperature: 0.3
@@ -4712,7 +4844,7 @@ function createResearchCrewConfig(options = {}) {
4712
4844
  {
4713
4845
  name: "analyst",
4714
4846
  role: analystRole,
4715
- model: options.model ?? "claude-sonnet-4-20250514",
4847
+ model: options.model ?? "claude-opus-4-8",
4716
4848
  provider: options.provider ?? "anthropic",
4717
4849
  tools: ["calculator", "data-analysis", ...options.tools ?? []],
4718
4850
  temperature: 0.2
@@ -4722,7 +4854,7 @@ function createResearchCrewConfig(options = {}) {
4722
4854
  agents.push({
4723
4855
  name: "writer",
4724
4856
  role: writerRole,
4725
- model: options.model ?? "claude-sonnet-4-20250514",
4857
+ model: options.model ?? "claude-opus-4-8",
4726
4858
  provider: options.provider ?? "anthropic",
4727
4859
  tools: ["text-editor", ...options.tools ?? []],
4728
4860
  temperature: 0.5
@@ -4935,7 +5067,7 @@ Your target audience is: ${options.audience}` : "";
4935
5067
  ...editorRole,
4936
5068
  systemPrompt: editorRole.systemPrompt + contentTypePrompt + audiencePrompt
4937
5069
  },
4938
- model: options.model ?? "claude-sonnet-4-20250514",
5070
+ model: options.model ?? "claude-opus-4-8",
4939
5071
  provider: options.provider ?? "anthropic",
4940
5072
  tools: ["text-editor", ...options.tools ?? []],
4941
5073
  temperature: 0.3
@@ -4946,7 +5078,7 @@ Your target audience is: ${options.audience}` : "";
4946
5078
  ...writerRole2,
4947
5079
  systemPrompt: writerRole2.systemPrompt + contentTypePrompt + audiencePrompt
4948
5080
  },
4949
- model: options.model ?? "claude-sonnet-4-20250514",
5081
+ model: options.model ?? "claude-opus-4-8",
4950
5082
  provider: options.provider ?? "anthropic",
4951
5083
  tools: ["web-search", "text-editor", ...options.tools ?? []],
4952
5084
  temperature: 0.7
@@ -4954,7 +5086,7 @@ Your target audience is: ${options.audience}` : "";
4954
5086
  {
4955
5087
  name: "proofreader",
4956
5088
  role: proofreaderRole,
4957
- model: options.model ?? "claude-sonnet-4-20250514",
5089
+ model: options.model ?? "claude-opus-4-8",
4958
5090
  provider: options.provider ?? "anthropic",
4959
5091
  tools: ["grammar-checker", "spell-checker", ...options.tools ?? []],
4960
5092
  temperature: 0.1
@@ -5193,7 +5325,7 @@ You specialize in: ${options.languages.join(", ")}` : "";
5193
5325
  ...seniorDeveloperRole,
5194
5326
  systemPrompt: seniorDeveloperRole.systemPrompt + languagePrompt + strictnessPrompt
5195
5327
  },
5196
- model: options.model ?? "claude-sonnet-4-20250514",
5328
+ model: options.model ?? "claude-opus-4-8",
5197
5329
  provider: options.provider ?? "anthropic",
5198
5330
  tools: ["code-analyzer", "linter", ...options.tools ?? []],
5199
5331
  temperature: 0.2
@@ -5206,7 +5338,7 @@ You specialize in: ${options.languages.join(", ")}` : "";
5206
5338
  ...securityAnalystRole,
5207
5339
  systemPrompt: securityAnalystRole.systemPrompt + languagePrompt
5208
5340
  },
5209
- model: options.model ?? "claude-sonnet-4-20250514",
5341
+ model: options.model ?? "claude-opus-4-8",
5210
5342
  provider: options.provider ?? "anthropic",
5211
5343
  tools: [
5212
5344
  "security-scanner",
@@ -5223,7 +5355,7 @@ You specialize in: ${options.languages.join(", ")}` : "";
5223
5355
  ...performanceEngineerRole,
5224
5356
  systemPrompt: performanceEngineerRole.systemPrompt + languagePrompt
5225
5357
  },
5226
- model: options.model ?? "claude-sonnet-4-20250514",
5358
+ model: options.model ?? "claude-opus-4-8",
5227
5359
  provider: options.provider ?? "anthropic",
5228
5360
  tools: ["profiler", "complexity-analyzer", ...options.tools ?? []],
5229
5361
  temperature: 0.2
@@ -5481,7 +5613,7 @@ You support ${options.productName}.` : "";
5481
5613
  ...tier1AgentRole,
5482
5614
  systemPrompt: tier1AgentRole.systemPrompt + contextAddition
5483
5615
  },
5484
- model: options.model ?? "claude-sonnet-4-20250514",
5616
+ model: options.model ?? "claude-opus-4-8",
5485
5617
  provider: options.provider ?? "anthropic",
5486
5618
  tools: ["knowledge-base", "ticket-system", ...options.tools ?? []],
5487
5619
  temperature: 0.4
@@ -5494,7 +5626,7 @@ You support ${options.productName}.` : "";
5494
5626
  ...specialistRole,
5495
5627
  systemPrompt: specialistRole.systemPrompt + contextAddition
5496
5628
  },
5497
- model: options.model ?? "claude-sonnet-4-20250514",
5629
+ model: options.model ?? "claude-opus-4-8",
5498
5630
  provider: options.provider ?? "anthropic",
5499
5631
  tools: [
5500
5632
  "diagnostic-tools",
@@ -5512,7 +5644,7 @@ You support ${options.productName}.` : "";
5512
5644
  ...escalationManagerRole,
5513
5645
  systemPrompt: escalationManagerRole.systemPrompt + contextAddition
5514
5646
  },
5515
- model: options.model ?? "claude-sonnet-4-20250514",
5647
+ model: options.model ?? "claude-opus-4-8",
5516
5648
  provider: options.provider ?? "anthropic",
5517
5649
  tools: [
5518
5650
  "crm",
@@ -11,8 +11,8 @@ import {
11
11
  createResearchCrewConfig,
12
12
  createWritingCrew,
13
13
  createWritingCrewConfig
14
- } from "../chunk-G3PAPYOI.mjs";
15
- import "../chunk-QMK3HWFX.mjs";
14
+ } from "../chunk-6JLVFEU6.mjs";
15
+ import "../chunk-V6VK6BOL.mjs";
16
16
  export {
17
17
  CodeReviewTasks,
18
18
  CustomerSupportTasks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lov3kaizen/agentsea-crews",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Multi-agent orchestration framework for AgentSea. Build, compose, and orchestrate agent crews with role-based coordination, task delegation, and workflow automation.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -32,15 +32,15 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^20.11.0",
35
- "@vitest/coverage-v8": "^1.2.0",
35
+ "@vitest/coverage-v8": "^3.2.6",
36
36
  "tsup": "^8.0.1",
37
37
  "typescript": "^5.3.3",
38
- "vitest": "^1.2.0"
38
+ "vitest": "^3.2.6"
39
39
  },
40
40
  "peerDependencies": {
41
- "@nestjs/common": "^10.0.0",
42
- "@nestjs/core": "^10.0.0",
43
- "@lov3kaizen/agentsea-core": "0.6.0"
41
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
42
+ "@nestjs/core": "^10.0.0 || ^11.0.0",
43
+ "@lov3kaizen/agentsea-core": "1.1.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@nestjs/common": {
@@ -64,7 +64,7 @@
64
64
  "typescript"
65
65
  ],
66
66
  "engines": {
67
- "node": ">=18.0.0"
67
+ "node": ">=20.0.0"
68
68
  },
69
69
  "author": "lovekaizen",
70
70
  "license": "MIT",