agentfootprint 2.3.0 → 2.4.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.
Files changed (61) hide show
  1. package/README.md +277 -249
  2. package/dist/core/Agent.js +16 -0
  3. package/dist/core/Agent.js.map +1 -1
  4. package/dist/esm/core/Agent.js +16 -0
  5. package/dist/esm/core/Agent.js.map +1 -1
  6. package/dist/esm/index.js +1 -1
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/esm/lib/injection-engine/SkillRegistry.js +83 -0
  9. package/dist/esm/lib/injection-engine/SkillRegistry.js.map +1 -0
  10. package/dist/esm/lib/injection-engine/factories/defineSkill.js +34 -0
  11. package/dist/esm/lib/injection-engine/factories/defineSkill.js.map +1 -1
  12. package/dist/esm/lib/injection-engine/index.js +2 -1
  13. package/dist/esm/lib/injection-engine/index.js.map +1 -1
  14. package/dist/esm/lib/injection-engine/types.js.map +1 -1
  15. package/dist/index.js +3 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/lib/injection-engine/SkillRegistry.js +87 -0
  18. package/dist/lib/injection-engine/SkillRegistry.js.map +1 -0
  19. package/dist/lib/injection-engine/factories/defineSkill.js +36 -1
  20. package/dist/lib/injection-engine/factories/defineSkill.js.map +1 -1
  21. package/dist/lib/injection-engine/index.js +4 -1
  22. package/dist/lib/injection-engine/index.js.map +1 -1
  23. package/dist/lib/injection-engine/types.js.map +1 -1
  24. package/dist/types/core/Agent.d.ts +14 -0
  25. package/dist/types/core/Agent.d.ts.map +1 -1
  26. package/dist/types/index.d.ts +1 -1
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/lib/injection-engine/SkillRegistry.d.ts +50 -0
  29. package/dist/types/lib/injection-engine/SkillRegistry.d.ts.map +1 -0
  30. package/dist/types/lib/injection-engine/factories/defineSkill.d.ts +72 -0
  31. package/dist/types/lib/injection-engine/factories/defineSkill.d.ts.map +1 -1
  32. package/dist/types/lib/injection-engine/index.d.ts +2 -1
  33. package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
  34. package/dist/types/lib/injection-engine/types.d.ts +10 -0
  35. package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
  36. package/package.json +27 -8
  37. package/README.proposed.md +0 -258
  38. package/dist/instructions.js +0 -21
  39. package/dist/instructions.js.map +0 -1
  40. package/dist/lib/instructions/defineInstruction.js +0 -35
  41. package/dist/lib/instructions/defineInstruction.js.map +0 -1
  42. package/dist/lib/instructions/evaluator.js +0 -38
  43. package/dist/lib/instructions/evaluator.js.map +0 -1
  44. package/dist/lib/instructions/index.js +0 -48
  45. package/dist/lib/instructions/index.js.map +0 -1
  46. package/dist/lib/instructions/types.js +0 -22
  47. package/dist/lib/instructions/types.js.map +0 -1
  48. package/dist/memory/conversationHelpers.js +0 -39
  49. package/dist/memory/conversationHelpers.js.map +0 -1
  50. package/dist/types/instructions.d.ts +0 -5
  51. package/dist/types/instructions.d.ts.map +0 -1
  52. package/dist/types/lib/instructions/defineInstruction.d.ts +0 -22
  53. package/dist/types/lib/instructions/defineInstruction.d.ts.map +0 -1
  54. package/dist/types/lib/instructions/evaluator.d.ts +0 -11
  55. package/dist/types/lib/instructions/evaluator.d.ts.map +0 -1
  56. package/dist/types/lib/instructions/index.d.ts +0 -44
  57. package/dist/types/lib/instructions/index.d.ts.map +0 -1
  58. package/dist/types/lib/instructions/types.d.ts +0 -100
  59. package/dist/types/lib/instructions/types.d.ts.map +0 -1
  60. package/dist/types/memory/conversationHelpers.d.ts +0 -19
  61. package/dist/types/memory/conversationHelpers.d.ts.map +0 -1
@@ -1,100 +0,0 @@
1
- /**
2
- * Instructions — types.
3
- *
4
- * An Instruction is a declarative rule for conditional system-prompt
5
- * injection. The agent evaluates each Instruction's `activeWhen`
6
- * predicate at the start of every iteration; matching instructions'
7
- * `prompt` text is prepended to the system prompt for that iteration.
8
- *
9
- * This is the rule-based flavor of the unified context-engineering
10
- * model: slot=system-prompt, role=system, timing=per-iteration,
11
- * decision=rule. (Compare with Skills: timing=on-activation,
12
- * decision=LLM-guided.)
13
- *
14
- * Pattern: Strategy (GoF) — each Instruction is a strategy for
15
- * "should I add this prompt to the next iteration?"
16
- * Role: Consumer-facing shape. Agent.create(...).instruction(...).
17
- * Emits: `agentfootprint.context.injected` with source='instruction'
18
- * when an instruction activates.
19
- */
20
- import type { Tool } from '../../core/tools.js';
21
- /**
22
- * Read-only snapshot of the agent's state that an Instruction can
23
- * inspect to decide activation. Includes only the fields a predicate
24
- * can safely depend on — internal mutable state is hidden.
25
- */
26
- export interface InstructionContext {
27
- /** Current ReAct iteration (1-based). */
28
- readonly iteration: number;
29
- /** The current user message that started this turn. */
30
- readonly userMessage: string;
31
- /**
32
- * Conversation history up to (but not including) the current
33
- * iteration's LLM call. Includes system / user / assistant / tool
34
- * messages from prior iterations of the same turn.
35
- */
36
- readonly history: ReadonlyArray<{
37
- readonly role: 'system' | 'user' | 'assistant' | 'tool';
38
- readonly content: string;
39
- readonly toolName?: string;
40
- }>;
41
- /**
42
- * The most recent tool result, if the previous iteration ended in a
43
- * tool call. Undefined on the first iteration of a turn.
44
- */
45
- readonly lastToolResult?: {
46
- readonly toolName: string;
47
- readonly result: string;
48
- };
49
- /** Custom decision-scope state the consumer placed via Agent options. */
50
- readonly decision?: Readonly<Record<string, unknown>>;
51
- }
52
- /**
53
- * A single declarative instruction.
54
- *
55
- * @example
56
- * const calmTone = defineInstruction({
57
- * id: 'calm-tone',
58
- * description: 'Use a calm, empathetic tone after the user expresses frustration.',
59
- * activeWhen: (ctx) => ctx.userMessage.includes('frustrated')
60
- * || ctx.userMessage.includes('angry'),
61
- * prompt: 'The user is upset. Respond calmly. Acknowledge feelings before facts.',
62
- * });
63
- *
64
- * const agent = Agent.create({ provider }).instruction(calmTone).build();
65
- */
66
- export interface Instruction {
67
- /** Unique id — used for observability + de-duplication. */
68
- readonly id: string;
69
- /** Human-readable description (Lens / docs / debug). */
70
- readonly description?: string;
71
- /**
72
- * Predicate to decide activation. Synchronous; side-effect free.
73
- * If omitted, the instruction is always active. Predicates that
74
- * throw are skipped (fail-open) and the error is surfaced via the
75
- * emit channel for observability — they don't crash the run.
76
- */
77
- readonly activeWhen?: (ctx: InstructionContext) => boolean;
78
- /** Text appended to the next iteration's system prompt when active. */
79
- readonly prompt?: string;
80
- /**
81
- * Tools to add to the agent's tool registry when the instruction is
82
- * active. Merged with the agent's base tools (later instructions win
83
- * on duplicate ids). Empty by default.
84
- */
85
- readonly tools?: readonly Tool[];
86
- }
87
- /**
88
- * @internal
89
- * Branded result returned by `evaluateInstructions()`. Lets the
90
- * agent's pre-LLM stage consume the projection without re-running
91
- * the predicates.
92
- */
93
- export interface InstructionEvaluation {
94
- readonly active: readonly Instruction[];
95
- readonly skipped: ReadonlyArray<{
96
- readonly id: string;
97
- readonly error: string;
98
- }>;
99
- }
100
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/instructions/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IACvD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;QAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;QACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC,CAAC;IACH;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE;QACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACvD;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,WAAW;IAC1B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC;IAC3D,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClF"}
@@ -1,19 +0,0 @@
1
- /**
2
- * Pure functions for conversation message management.
3
- * No state — just transformations on message arrays.
4
- */
5
- import type { Message, AssistantMessage, ToolResultMessage } from '../types';
6
- /** Append a message to the conversation. Returns new array. */
7
- export declare function appendMessage(messages: Message[], message: Message): Message[];
8
- /** Get the last message in the conversation. */
9
- export declare function lastMessage(messages: Message[]): Message | undefined;
10
- /** Get the last assistant message. */
11
- export declare function lastAssistantMessage(messages: Message[]): AssistantMessage | undefined;
12
- /** Check if the last assistant message has tool calls. */
13
- export declare function lastMessageHasToolCalls(messages: Message[]): boolean;
14
- /** Create tool result messages from a map of tool call ID → result. */
15
- export declare function createToolResults(results: Array<{
16
- toolCallId: string;
17
- content: string;
18
- }>): ToolResultMessage[];
19
- //# sourceMappingURL=conversationHelpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conversationHelpers.d.ts","sourceRoot":"","sources":["../../../src/memory/conversationHelpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG7E,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,CAE9E;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,GAAG,SAAS,CAEpE;AAED,sCAAsC;AACtC,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,gBAAgB,GAAG,SAAS,CAKtF;AAED,0DAA0D;AAC1D,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAGpE;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,KAAK,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GACtD,iBAAiB,EAAE,CAErB"}