bazis 0.98.34 → 0.99.1

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.
@@ -49,8 +49,6 @@ export function buildModuleTemplates(
49
49
  return [
50
50
  ...base,
51
51
  { relativePath: `background/${naming.module}.reporter.ts`, content: statsReporterFile(naming) },
52
- { relativePath: `ai/agents/${naming.module}Analyst.agent.ts`, content: agentFile(naming) },
53
- { relativePath: `ai/contracts/${naming.module}.brief.ts`, content: aiContractsFile(naming) },
54
52
  { relativePath: `ai/tools/${naming.module}Summary.tool.ts`, content: aiToolFile(naming) },
55
53
  ];
56
54
  }
@@ -59,14 +57,12 @@ function moduleFile(n: ModuleNaming, profile: ModuleTemplateProfile): string {
59
57
  const moduleImport = "import { Module, scoped } from \"bazis/core/di\";";
60
58
  const backgroundImport = profile === "full" ? `import { ${n.module}Reporter } from "./background/${n.module}.reporter";\n` : "";
61
59
  const aiImports = profile === "full"
62
- ? `import { ${n.module}AnalystAgent } from "./ai/agents/${n.module}Analyst.agent";
63
- import { ${n.module}SummaryTool } from "./ai/tools/${n.module}Summary.tool";
60
+ ? `import { ${n.module}SummaryTool } from "./ai/tools/${n.module}Summary.tool";
64
61
  `
65
62
  : "";
66
63
  const backgroundLine = profile === "full" ? ` background: [${n.module}Reporter],\n` : "";
67
64
  const aiLines = profile === "full"
68
- ? ` agents: [${n.module}AnalystAgent],
69
- tools: [${n.module}SummaryTool],
65
+ ? ` tools: [${n.module}SummaryTool],
70
66
  `
71
67
  : "";
72
68
 
@@ -400,23 +396,6 @@ export class ${n.module}Reporter extends PeriodicBackgroundService {
400
396
  `;
401
397
  }
402
398
 
403
- function aiContractsFile(n: ModuleNaming): string {
404
- return `import { Validator } from "bazis/library/validation";
405
-
406
- export class Prepare${n.module}BriefRequest {
407
- @Validator({ required: true, minLength: 3 })
408
- topic!: string;
409
-
410
- @Validator({ required: true, minLength: 3 })
411
- audience = "operators";
412
- }
413
-
414
- export class ${n.module}BriefDocument {
415
- title = "";
416
- bullets: string[] = [];
417
- }
418
- `;
419
- }
420
399
 
421
400
  function aiToolFile(n: ModuleNaming): string {
422
401
  return `import { Tool, type AgentToolExecutionContext } from "bazis/core/agent";
@@ -458,40 +437,3 @@ export class ${n.module}SummaryTool {
458
437
  `;
459
438
  }
460
439
 
461
- function agentFile(n: ModuleNaming): string {
462
- return `import { Agent, Task, agentOutput } from "bazis/core/agent";
463
- import { Prepare${n.module}BriefRequest, ${n.module}BriefDocument } from "../contracts/${n.module}.brief";
464
- import { ${n.module}SummaryTool } from "../tools/${n.module}Summary.tool";
465
-
466
- @Agent({
467
- name: "${n.route}-analyst",
468
- role: "${n.route} analyst",
469
- sections: [
470
- {
471
- kind: "developer",
472
- content: "Write short, concrete operational summaries of the ${n.route} domain.",
473
- },
474
- {
475
- kind: "tool-policy",
476
- content: "Use read tools before the final summary. Do not make up data.",
477
- },
478
- ],
479
- tools: [${n.module}SummaryTool],
480
- modelProfile: "reasoning",
481
- maxSteps: 3,
482
- })
483
- export class ${n.module}AnalystAgent {
484
- @Task({
485
- name: "prepare-${n.route}-brief",
486
- description: "Prepare a short ${n.route} summary from the current module data.",
487
- input: Prepare${n.module}BriefRequest,
488
- output: ${n.module}BriefDocument,
489
- modelProfile: "reasoning",
490
- maxSteps: 3,
491
- })
492
- prepareBrief(_input: Prepare${n.module}BriefRequest): ${n.module}BriefDocument {
493
- return agentOutput();
494
- }
495
- }
496
- `;
497
- }
@@ -66,9 +66,7 @@ adapters that access it.
66
66
  | ${e}Response / ${m}Summary / to${e}Response | [responses](http/contracts/${m}.responses.ts) | ORM entity | Public data projection |
67
67
  | ${m}ListQuery | [list](http/contracts/${m}List.query.ts) | Query string | ListQuery, filters/sorting/pages |
68
68
  ${profile === "full" ? `| ${m}Reporter | [background](background/${m}.reporter.ts) | ServiceProvider, Logger, AbortSignal | Runs count and logs it |
69
- | ${m}SummaryTool | [tool](ai/tools/${m}Summary.tool.ts) | I${m}Service, input, context | Summary for the agent |
70
- | ${m}AnalystAgent | [agent](ai/agents/${m}Analyst.agent.ts) | Prepare${m}BriefRequest | ${m}BriefDocument via AgentRuntime |
71
- | AI DTO | [contracts](ai/contracts/${m}.brief.ts) | topic, audience | title, bullets |
69
+ | ${m}SummaryTool | [tool](ai/tools/${m}Summary.tool.ts) | I${m}Service, input, context | Summary for an agent |
72
70
  ` : ""}
73
71
 
74
72
  ## Wiring, DI and data
@@ -80,8 +78,8 @@ I${m}Service → ${m}Service, scoped lifetime. The context and DbSet belong to t
80
78
  ${profile === "full" ? `${m}SummaryTool is listed in tools: [${m}SummaryTool]; the framework registers it as scoped, the tool is not exported.
81
79
  The service is scoped; its keyed @Cacheable works when the host installs the cache (runApp cache: memory()).
82
80
  The background service gets its own scope per tick and disposes it in finally.
83
- The host also provides auth from src/app/modules/auth (TokenKind.Admin/Client),
84
- AgentRuntime and the reasoning modelProfile. The CLI does not create them.
81
+ The host also provides auth from src/app/modules/auth (TokenKind.Admin/Client)
82
+ and an LLM connector, which registers AgentRuntime. The CLI does not create them.
85
83
  ` : ""}Constructor dependencies, including ${m}DbContext, are wired by codegen.
86
84
  No manual deps arrays. UI, events and own configuration are not used.
87
85
 
@@ -167,21 +165,19 @@ AbortSignal from the runtime, creates a scope, runs count and logs it unless
167
165
  the signal is aborted; dispose always runs. The SQL itself is not cancelled by
168
166
  this signal.
169
167
 
170
- Tool ${n.route}.summary: execute(input, context), sideEffect read.
171
- Agent ${n.route}-analyst: prepareBrief(input), task prepare-${n.route}-brief;
172
- modelProfile reasoning, maxSteps 3. The agentOutput method is a declaration
173
- for the runtime. Calling prepareBrief directly does not run the LLM.
168
+ Tool ${n.route}.summary: execute(input, context), sideEffect read. Agents are
169
+ data, not classes: an agent definition names the tool in toolNames and runs
170
+ with AgentRuntime.run(definition, { input }).
174
171
 
175
- | AI input field | Type / source | Required | null | Default | Check | Example |
172
+ | Tool input field | Type / source | Required | null | Default | Check | Example |
176
173
  | --- | --- | --- | --- | --- | --- | --- |
177
- | topic | string / tool input or Prepare${n.module}BriefRequest | Yes | no | none | Validator required, minLength 3 | Daily summary |
178
- | audience | string / Prepare${n.module}BriefRequest | Yes by Validator | no | operators when the DTO is created | Validator required, minLength 3 | operators |
179
- | context | AgentToolExecutionContext / runtime | For the tool | no | runtime | agentName comes from the server context | agentName: ${n.route}-analyst |
174
+ | topic | string / tool input | Yes | no | none | Validator required, minLength 3 | Daily summary |
175
+ | context | AgentToolExecutionContext / runtime | Yes | no | runtime | agentName comes from the running agent definition | agentName: ${n.route}-analyst |
180
176
 
181
177
  Tool output: topic string, count number, names string[], agentName string
182
- (empty when the context has no name). Agent output: title string, bullets
183
- string[]. AgentRuntime validates AI inputs and reports their errors; the
184
- scaffold adds no own permission checks for direct DI/tool calls. The host
185
- decides which tools are allowed. The scaffold does not retry the tool.
178
+ (empty when the context has no name). AgentRuntime validates the tool input
179
+ and reports its errors to the model; the scaffold adds no own permission
180
+ checks. Which agents may call the tool is decided by their definitions'
181
+ toolNames. The scaffold does not retry the tool.
186
182
  `;
187
183
  }
@@ -463,105 +463,11 @@ export class DefaultAgentContextBuilder implements AgentContextBuilder {
463
463
  return estimate;
464
464
  }
465
465
 
466
+ /** The definition's instructions are the system prompt, sent as written. */
466
467
  private promptMessage(agent: AgentDefinition): AgentMessage | undefined {
467
- const lines: string[] = [];
468
- if (agent.metadata.role !== undefined) {
469
- lines.push(`Role: ${agent.metadata.role}`);
470
- }
471
- if (agent.metadata.description !== undefined) {
472
- lines.push(`Description: ${agent.metadata.description}`);
473
- }
474
- if (agent.metadata.goal !== undefined) {
475
- lines.push(`Goal: ${agent.metadata.goal}`);
476
- }
477
- if (agent.metadata.instructions.length > 0) {
478
- lines.push("Instructions:");
479
- lines.push(...agent.metadata.instructions.map((item) => `- ${item}`));
480
- }
481
- if (agent.metadata.constraints.length > 0) {
482
- lines.push("Constraints:");
483
- lines.push(...agent.metadata.constraints.map((item) => `- ${item}`));
484
- }
485
- for (let index = 0; index < agent.metadata.sections.length; index += 1) {
486
- appendPromptSection(lines, agent.metadata.sections[index] as (typeof agent.metadata.sections)[number]);
487
- }
488
-
489
- const prompt = agent.prompt?.metadata;
490
- if (prompt !== undefined) {
491
- if (prompt.description !== undefined) {
492
- lines.push(`Prompt description: ${prompt.description}`);
493
- }
494
- if (prompt.version !== undefined) {
495
- lines.push(`Prompt version: ${prompt.version}`);
496
- }
497
- if (prompt.role !== undefined) {
498
- lines.push(`Prompt role: ${prompt.role}`);
499
- }
500
- if (prompt.goal !== undefined) {
501
- lines.push(`Goal: ${prompt.goal}`);
502
- }
503
- if (prompt.instructions.length > 0) {
504
- lines.push("Instructions:");
505
- lines.push(...prompt.instructions.map((item) => `- ${item}`));
506
- }
507
- if (prompt.constraints.length > 0) {
508
- lines.push("Constraints:");
509
- lines.push(...prompt.constraints.map((item) => `- ${item}`));
510
- }
511
- for (let index = 0; index < prompt.sections.length; index += 1) {
512
- appendPromptSection(lines, prompt.sections[index] as (typeof prompt.sections)[number]);
513
- }
514
- }
515
-
516
- return lines.length === 0
468
+ const instructions = agent.instructions.trim();
469
+ return instructions.length === 0
517
470
  ? undefined
518
- : agentMessage("system", lines.join("\n"), {
519
- metadata: {
520
- agentName: agent.metadata.name,
521
- promptName: prompt?.name ?? null,
522
- promptSectionKinds: prompt?.sections.map((section) => section.kind) ?? [],
523
- },
524
- });
525
- }
526
- }
527
-
528
- function appendPromptSection(
529
- lines: string[],
530
- section: { readonly kind: string; readonly title?: string; readonly content: readonly string[] },
531
- ): void {
532
- lines.push(`${section.title ?? promptSectionTitle(section.kind)}:`);
533
- if (section.content.length === 1) {
534
- lines.push(section.content[0] as string);
535
- return;
536
- }
537
- lines.push(...section.content.map((item) => `- ${item}`));
538
- }
539
-
540
- function promptSectionTitle(kind: string): string {
541
- switch (kind) {
542
- case "system":
543
- return "System";
544
- case "developer":
545
- return "Developer";
546
- case "role":
547
- return "Role";
548
- case "task":
549
- return "Task";
550
- case "instructions":
551
- return "Instructions";
552
- case "constraints":
553
- return "Constraints";
554
- case "examples":
555
- return "Examples";
556
- case "output":
557
- return "Output format";
558
- case "tool-policy":
559
- return "Tool policy";
560
- case "memory":
561
- return "Memory";
562
- case "knowledge":
563
- return "Knowledge";
564
- default:
565
- return "Prompt section";
471
+ : agentMessage("system", instructions, { metadata: { agentName: agent.name } });
566
472
  }
567
473
  }