Skip to content

Commit 398d313

Browse files
committed
dynamic-docs
1 parent 74dc2c2 commit 398d313

3 files changed

Lines changed: 83 additions & 41 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agent-swarm-kit",
3-
"version": "1.1.70",
3+
"version": "1.1.71",
44
"description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
55
"author": {
66
"name": "Petr Tripolsky",

src/lib/services/base/DocService.ts

Lines changed: 80 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,11 @@ export class DocService {
355355
* @private
356356
*/
357357
private writeAgentDoc = execpool(
358-
async (agentSchema: IAgentSchemaInternal, prefix: string, dirName: string) => {
358+
async (
359+
agentSchema: IAgentSchemaInternal,
360+
prefix: string,
361+
dirName: string
362+
) => {
359363
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
360364
this.loggerService.info("docService writeAgentDoc", {
361365
agentSchema,
@@ -403,43 +407,62 @@ export class DocService {
403407
}
404408
}
405409

406-
if (typeof agentSchema.prompt === "string") {
410+
const getPrompt = async () => {
411+
try {
412+
if (typeof agentSchema.prompt === "string") {
413+
return agentSchema.prompt;
414+
}
415+
if (typeof agentSchema.prompt === "function") {
416+
return await agentSchema.prompt("docs", agentSchema.agentName);
417+
}
418+
return null;
419+
} catch {
420+
return null;
421+
}
422+
};
423+
424+
const prompt = await getPrompt();
425+
426+
if (prompt) {
407427
result.push(`## Main prompt`);
408428
result.push("");
409429
result.push("```");
410-
result.push(agentSchema.prompt);
430+
result.push(prompt);
411431
result.push("```");
412432
result.push("");
413433
}
414434

415-
if (agentSchema.systemStatic || agentSchema.system) {
416-
result.push(`## System prompt`);
417-
result.push("");
418-
let offset = 0;
419-
if (agentSchema.systemStatic) {
420-
for (let i = 0; i !== agentSchema.systemStatic.length; i++) {
421-
if (!agentSchema.systemStatic[i]) {
422-
continue;
423-
}
424-
result.push(`${i + 1}. \`${agentSchema.systemStatic[i]}\``);
425-
result.push("");
426-
offset = i;
435+
const getSystem = async () => {
436+
let system: string[] = [];
437+
try {
438+
if (agentSchema.systemStatic) {
439+
system = system.concat(agentSchema.systemStatic);
427440
}
428-
}
429-
if (agentSchema.system) {
430-
for (let i = 0; i !== agentSchema.system.length; i++) {
431-
if (!agentSchema.system[i]) {
432-
continue;
433-
}
434-
result.push(`${i + offset + 1}. \`${agentSchema.system[i]}\``);
435-
result.push("");
441+
if (agentSchema.system) {
442+
system = system.concat(agentSchema.system);
436443
}
444+
if (agentSchema.systemDynamic) {
445+
system = system.concat(
446+
await agentSchema.systemDynamic("docs", agentSchema.agentName)
447+
);
448+
}
449+
} finally {
450+
return system;
437451
}
438-
}
452+
};
439453

440-
if (agentSchema.systemDynamic) {
441-
result.push("***Dynamic system prompt found***");
454+
const system = await getSystem();
455+
456+
if (system.length) {
457+
result.push(`## System prompt`);
442458
result.push("");
459+
for (let i = 0; i !== system.length; i++) {
460+
if (!system[i]) {
461+
continue;
462+
}
463+
result.push(`${i + 1}. \`${system[i]}\``);
464+
result.push("");
465+
}
443466
}
444467

445468
if (agentSchema.dependsOn) {
@@ -484,22 +507,41 @@ export class DocService {
484507
}
485508
}
486509

487-
if (agentSchema.tools) {
488-
result.push(`## Used tools`);
489-
result.push("");
490-
for (let i = 0; i !== agentSchema.tools.length; i++) {
491-
if (!agentSchema.tools[i]) {
492-
continue;
510+
const getTools = async () => {
511+
try {
512+
if (!agentSchema.tools) {
513+
return null;
493514
}
494-
const {
495-
function: fn,
496-
docNote,
497-
callbacks,
498-
} = this.toolSchemaService.get(agentSchema.tools[i]);
515+
return await Promise.all(
516+
agentSchema.tools
517+
.map((toolName) => this.toolSchemaService.get(toolName))
518+
.map(async (tool) => {
519+
const { function: upperFn, ...other } = tool;
520+
const fn =
521+
typeof upperFn === "function"
522+
? await upperFn("docs", agentSchema.agentName)
523+
: upperFn;
524+
return {
525+
...other,
526+
function: fn,
527+
};
528+
})
529+
);
530+
} catch {
531+
return null;
532+
}
533+
};
499534

500-
if (typeof fn === "function") {
535+
const tools = await getTools();
536+
537+
if (tools) {
538+
result.push(`## Used tools`);
539+
result.push("");
540+
for (let i = 0; i !== tools.length; i++) {
541+
if (!tools[i]) {
501542
continue;
502543
}
544+
const { function: fn, docNote, callbacks } = tools[i];
503545

504546
result.push(`### ${i + 1}. ${agentSchema.tools[i]}`);
505547

0 commit comments

Comments
 (0)