art-framework 0.4.7 → 0.4.11

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 CHANGED
@@ -437,52 +437,402 @@ declare class LLMStreamSocket extends TypedSocket<StreamEvent, StreamEventTypeFi
437
437
  notifyStreamEvent(event: StreamEvent): void;
438
438
  }
439
439
 
440
+ /**
441
+ * Represents the current status of a TodoItem within the PES Agent's execution plan.
442
+ * These states track the lifecycle of individual steps throughout the agent's processing.
443
+ *
444
+ * @enum {string}
445
+ */
440
446
  declare enum TodoItemStatus {
447
+ /**
448
+ * The item has been created but has not yet started execution.
449
+ * This is the initial state for all newly planned items.
450
+ */
441
451
  PENDING = "pending",
452
+ /**
453
+ * The item is currently being executed by the agent.
454
+ * Only one item should be in this state at a time per thread.
455
+ */
442
456
  IN_PROGRESS = "in_progress",
457
+ /**
458
+ * The item has been successfully completed.
459
+ * The agent will not re-execute items in this state.
460
+ */
443
461
  COMPLETED = "completed",
462
+ /**
463
+ * The item execution failed and could not be completed.
464
+ * The agent may retry the item or skip it based on configuration.
465
+ */
444
466
  FAILED = "failed",
467
+ /**
468
+ * The item was cancelled before execution could complete.
469
+ * This may occur due to user intervention, timeout, or agent decision.
470
+ */
445
471
  CANCELLED = "cancelled",
472
+ /**
473
+ * The item is waiting for external conditions to be met.
474
+ * This is typically used for A2A (Agent-to-Agent) tasks waiting for remote completion.
475
+ */
446
476
  WAITING = "waiting"
447
477
  }
478
+ /**
479
+ * Represents a single step or task in the PES Agent's execution plan.
480
+ * Each TodoItem corresponds to one action the agent needs to take, which could be
481
+ * a tool call, a reasoning step, or a subtask.
482
+ *
483
+ * @interface TodoItem
484
+ */
448
485
  interface TodoItem {
486
+ /**
487
+ * A unique identifier for this specific todo item.
488
+ * This ID is used for tracking, logging, and referencing the item across systems.
489
+ * @property {string} id
490
+ */
449
491
  id: string;
492
+ /**
493
+ * A human-readable description of what this item accomplishes.
494
+ * This description is typically generated by the planning LLM and should be clear and actionable.
495
+ * @property {string} description
496
+ */
450
497
  description: string;
498
+ /**
499
+ * The current execution status of this item.
500
+ * Values come from the {@link TodoItemStatus} enum.
501
+ * @property {TodoItemStatus} status
502
+ */
451
503
  status: TodoItemStatus;
504
+ /**
505
+ * An array of todo item IDs that must be completed before this item can start.
506
+ * This enables the agent to define task dependencies and execution order.
507
+ * If empty or undefined, the item has no dependencies and can execute immediately.
508
+ * @property {string[]} [dependencies]
509
+ */
452
510
  dependencies?: string[];
511
+ /**
512
+ * The type of execution step this item represents.
513
+ * - 'tool': The item requires executing one or more tools.
514
+ * - 'reasoning': The item requires LLM reasoning without external tool calls.
515
+ *
516
+ * This classification is part of the TAEF (Tool-Aware Execution Framework) system.
517
+ * @property {'tool' | 'reasoning'} [stepType]
518
+ */
453
519
  stepType?: 'tool' | 'reasoning';
520
+ /**
521
+ * For tool-type steps, an array of tool names that must be called during execution.
522
+ * This is used by TAEF for validation - if required tools are not called,
523
+ * the agent may be prompted to retry or the step may fail validation.
524
+ * @property {string[]} [requiredTools]
525
+ */
454
526
  requiredTools?: string[];
527
+ /**
528
+ * A description of the expected outcome for this item.
529
+ * This helps the LLM understand what success looks like and guides execution.
530
+ * @property {string} [expectedOutcome]
531
+ */
455
532
  expectedOutcome?: string;
533
+ /**
534
+ * The validation mode for tool execution in this item.
535
+ * - 'strict': Required tools must be called for the step to pass validation.
536
+ * - 'advisory': Required tools are recommended but not enforced.
537
+ *
538
+ * @property {'strict' | 'advisory'} [toolValidationMode]
539
+ */
456
540
  toolValidationMode?: 'strict' | 'advisory';
541
+ /**
542
+ * The actual result produced by executing this item.
543
+ * The structure depends on the step type and what was executed.
544
+ * @property {any} [result]
545
+ */
457
546
  result?: any;
547
+ /**
548
+ * An array of thought strings captured during execution.
549
+ * These represent the agent's internal reasoning for this specific item.
550
+ * @property {string[]} [thoughts]
551
+ */
458
552
  thoughts?: string[];
553
+ /**
554
+ * The tool calls that were planned for this item.
555
+ * This comes from the planning phase and represents the intended execution.
556
+ * @property {ParsedToolCall[]} [toolCalls]
557
+ */
459
558
  toolCalls?: ParsedToolCall[];
559
+ /**
560
+ * The tool calls that were actually executed during processing.
561
+ * This may differ from the planned calls if the agent modified its approach.
562
+ * @property {ParsedToolCall[]} [actualToolCalls]
563
+ */
460
564
  actualToolCalls?: ParsedToolCall[];
565
+ /**
566
+ * The results from all tool executions for this item.
567
+ * Includes both successful and failed tool attempts.
568
+ * @property {ToolResult[]} [toolResults]
569
+ */
461
570
  toolResults?: ToolResult[];
571
+ /**
572
+ * The validation status for this item's execution.
573
+ * - 'passed': The item passed all validation checks (e.g., required tools called).
574
+ * - 'failed': The item failed validation.
575
+ * - 'skipped': Validation was skipped for this item.
576
+ *
577
+ * @property {'passed' | 'failed' | 'skipped'} [validationStatus]
578
+ */
462
579
  validationStatus?: 'passed' | 'failed' | 'skipped';
580
+ /**
581
+ * The Unix timestamp (in milliseconds) when this item was created.
582
+ * This is used for tracking execution order and debugging.
583
+ * @property {number} createdTimestamp
584
+ */
463
585
  createdTimestamp: number;
586
+ /**
587
+ * The Unix timestamp (in milliseconds) when this item was last updated.
588
+ * This tracks the most recent modification to the item's state.
589
+ * @property {number} updatedTimestamp
590
+ */
464
591
  updatedTimestamp: number;
465
592
  }
593
+ /**
594
+ * Represents the persistent state data for a PES Agent instance associated with a thread.
595
+ * This state is saved to storage and persists across multiple execution cycles.
596
+ *
597
+ * @interface PESAgentStateData
598
+ */
466
599
  interface PESAgentStateData {
600
+ /**
601
+ * The thread ID this state belongs to.
602
+ * Links the state to a specific conversation thread.
603
+ * @property {string} threadId
604
+ */
467
605
  threadId: string;
606
+ /**
607
+ * The user's intent extracted from their query.
608
+ * This is a concise summary of what the user wants to accomplish.
609
+ * @property {string} intent
610
+ */
468
611
  intent: string;
612
+ /**
613
+ * A concise title for the thread, typically <= 10 words.
614
+ * Generated based on the user's query and context.
615
+ * @property {string} title
616
+ */
469
617
  title: string;
618
+ /**
619
+ * The high-level plan describing how the agent will address the user's intent.
620
+ * This is a human-readable description of the overall approach.
621
+ * @property {string} plan
622
+ */
470
623
  plan: string;
624
+ /**
625
+ * The complete list of todo items representing the execution plan.
626
+ * This array contains all steps the agent needs to take, in execution order.
627
+ * @property {TodoItem[]} todoList
628
+ */
471
629
  todoList: TodoItem[];
630
+ /**
631
+ * The ID of the todo item currently being executed.
632
+ * If null, no item is currently active (e.g., planning phase, completed state).
633
+ * @property {string | null} currentStepId
634
+ */
472
635
  currentStepId: string | null;
636
+ /**
637
+ * Indicates whether the agent is currently paused.
638
+ * This flag is set when HITL (Human-in-the-Loop) is triggered.
639
+ * @property {boolean} isPaused
640
+ */
473
641
  isPaused: boolean;
642
+ /**
643
+ * Suspension context for HITL (Human-in-the-Loop) functionality.
644
+ * When a blocking tool is called, the agent suspends execution and stores
645
+ * the context here to allow resumption after user input.
646
+ *
647
+ * @remarks
648
+ * This field is only present when the agent is in a suspended state.
649
+ *
650
+ * @property {object} [suspension]
651
+ * @property {string} [suspension.suspensionId] - Unique ID for this suspension event.
652
+ * @property {string} [suspension.itemId] - The TodoItem ID that triggered suspension.
653
+ * @property {ParsedToolCall} [suspension.toolCall] - The specific tool call that caused suspension.
654
+ * @property {ArtStandardPrompt} [suspension.iterationState] - Captured message history for resumption.
655
+ */
474
656
  suspension?: {
657
+ /**
658
+ * Unique identifier for this suspension event.
659
+ * Used to match resume requests to the correct suspension.
660
+ * @property {string} suspensionId
661
+ */
475
662
  suspensionId: string;
663
+ /**
664
+ * The ID of the TodoItem that triggered the suspension.
665
+ * This identifies which step is waiting for human input.
666
+ * @property {string} itemId
667
+ */
476
668
  itemId: string;
669
+ /**
670
+ * The specific tool call that triggered the suspension.
671
+ * This is the call that requires human approval or input.
672
+ * @property {import('./index').ParsedToolCall} toolCall
673
+ */
477
674
  toolCall: ParsedToolCall;
675
+ /**
676
+ * The captured message history (ArtStandardPrompt) at the time of suspension.
677
+ * This allows the agent to resume execution with the correct context.
678
+ * @property {import('./index').ArtStandardPrompt} iterationState
679
+ */
478
680
  iterationState: ArtStandardPrompt;
681
+ /**
682
+ * Tool results from successful tools in the same batch that completed
683
+ * before the suspending tool was executed.
684
+ * This prevents data loss when a batch contains both successful and suspending tools.
685
+ *
686
+ * @since 0.4.11
687
+ * @property {import('./index').ToolResult[]} [partialToolResults]
688
+ */
689
+ partialToolResults?: ToolResult[];
690
+ };
691
+ /**
692
+ * A table of outputs from completed steps.
693
+ * This persists step outputs for use during resume operations and synthesis.
694
+ * Keys are step IDs, values are {@link StepOutputEntry} objects.
695
+ *
696
+ * @remarks
697
+ * This enables cross-step data access and ensures that the synthesis phase
698
+ * has access to all relevant information from completed steps.
699
+ *
700
+ * @property {Record<string, StepOutputEntry>} [stepOutputs]
701
+ */
702
+ stepOutputs?: Record<string, StepOutputEntry>;
703
+ /**
704
+ * Pending A2A tasks that the agent is waiting for.
705
+ * This enables recovery after process restart by tracking submitted but incomplete A2A tasks.
706
+ *
707
+ * @since 0.4.11
708
+ * @property {object} [pendingA2ATasks]
709
+ */
710
+ pendingA2ATasks?: {
711
+ /**
712
+ * The IDs of the A2A tasks being waited on.
713
+ * @property {string[]} taskIds
714
+ */
715
+ taskIds: string[];
716
+ /**
717
+ * When the tasks were submitted.
718
+ * @property {number} submittedAt
719
+ */
720
+ submittedAt: number;
721
+ /**
722
+ * The TodoItem ID that triggered the A2A delegation.
723
+ * @property {string} itemId
724
+ */
725
+ itemId: string;
479
726
  };
480
727
  }
728
+ /**
729
+ * Represents a cached output entry from a completed execution step.
730
+ * These entries are persisted in the PESAgentStateData to enable resume
731
+ * capability and cross-step data access.
732
+ *
733
+ * @interface StepOutputEntry
734
+ */
735
+ interface StepOutputEntry {
736
+ /**
737
+ * The ID of the step this output belongs to.
738
+ * Matches the TodoItem.id.
739
+ * @property {string} stepId
740
+ */
741
+ stepId: string;
742
+ /**
743
+ * A description of the step.
744
+ * Matches the TodoItem.description.
745
+ * @property {string} description
746
+ */
747
+ description: string;
748
+ /**
749
+ * The type of step that produced this output.
750
+ * Matches the TodoItem.stepType.
751
+ * @property {'tool' | 'reasoning'} stepType
752
+ */
753
+ stepType: 'tool' | 'reasoning';
754
+ /**
755
+ * The final status of the step.
756
+ * Matches the TodoItem.status at completion time.
757
+ * @property {TodoItemStatus} status
758
+ */
759
+ status: TodoItemStatus;
760
+ /**
761
+ * The Unix timestamp (in milliseconds) when the step was completed.
762
+ * @property {number} [completedAt]
763
+ */
764
+ completedAt?: number;
765
+ /**
766
+ * The raw result from the step execution.
767
+ * This contains full, untruncated data for use by downstream steps.
768
+ * For tool steps, this includes tool outputs. For reasoning steps,
769
+ * this includes the LLM response.
770
+ *
771
+ * @remarks
772
+ * Unlike the step context which may truncate large outputs,
773
+ * this rawResult preserves the complete data.
774
+ *
775
+ * @property {any} [rawResult]
776
+ */
777
+ rawResult?: any;
778
+ /**
779
+ * Array of tool results if this was a tool-type step.
780
+ * Contains all tool execution attempts including errors.
781
+ * @property {ToolResult[]} [toolResults]
782
+ */
783
+ toolResults?: ToolResult[];
784
+ /**
785
+ * An optional summary of the step output.
786
+ * This provides a quick reference without loading the full rawResult.
787
+ * Useful for synthesis and debugging.
788
+ * @property {string} [summary]
789
+ */
790
+ summary?: string;
791
+ }
792
+ /**
793
+ * Represents the structured output from an LLM execution call during the PES Agent's
794
+ * execution phase. This is parsed from the raw LLM response.
795
+ *
796
+ * @interface ExecutionOutput
797
+ */
481
798
  interface ExecutionOutput {
799
+ /**
800
+ * The agent's thoughts or reasoning for this execution step.
801
+ * This may include decision-making logic or reflections.
802
+ * @property {string} [thoughts]
803
+ */
482
804
  thoughts?: string;
805
+ /**
806
+ * The main response content from the LLM.
807
+ * This is the primary textual output from the execution step.
808
+ * @property {string} [content]
809
+ */
483
810
  content?: string;
811
+ /**
812
+ * Any tool calls the LLM decided to make during execution.
813
+ * These are parsed and will be executed by the ToolSystem.
814
+ * @property {ParsedToolCall[]} [toolCalls]
815
+ */
484
816
  toolCalls?: ParsedToolCall[];
817
+ /**
818
+ * The agent's decision on how to proceed after this execution.
819
+ * - 'continue': Proceed to the next iteration or step.
820
+ * - 'wait': Pause and wait for external input (rare in execution phase).
821
+ * - 'complete_item': Mark the current item as complete and move to the next.
822
+ * - 'update_plan': Modify the execution plan (intent, todo list, etc.).
823
+ *
824
+ * @property {'continue' | 'wait' | 'complete_item' | 'update_plan'} [nextStepDecision]
825
+ */
485
826
  nextStepDecision?: 'continue' | 'wait' | 'complete_item' | 'update_plan';
827
+ /**
828
+ * Updates to the plan if the agent decided to modify it.
829
+ * This can include changes to intent, plan description, or the todo list.
830
+ *
831
+ * @property {object} [updatedPlan]
832
+ * @property {string} [updatedPlan.intent] - Modified intent statement.
833
+ * @property {string} [updatedPlan.plan] - Modified plan description.
834
+ * @property {TodoItem[]} [updatedPlan.todoList] - Modified list of todo items.
835
+ */
486
836
  updatedPlan?: {
487
837
  intent?: string;
488
838
  plan?: string;
@@ -1181,25 +1531,49 @@ interface StreamEvent {
1181
1531
  */
1182
1532
  data: any;
1183
1533
  /**
1184
- * Optional: Provides a more specific classification for `TOKEN` events,
1185
- * combining LLM-level detection (thinking/response, if available from adapter)
1186
- * and agent-level context (`callContext` from `CallOptions`).
1187
- * Used by consumers (like UI) to differentiate between intermediate thoughts and the final response.
1534
+ * Classification for TOKEN events, combining phase context and thinking detection.
1188
1535
  *
1189
- * - `LLM_THINKING`: Token identified by the adapter as part of the LLM's internal reasoning/thought process.
1190
- * - `LLM_RESPONSE`: Token identified by the adapter as part of the LLM's final response content.
1191
- * - `AGENT_THOUGHT_LLM_THINKING`: Token from an LLM call made in the 'AGENT_THOUGHT' context, identified as thinking.
1192
- * - `AGENT_THOUGHT_LLM_RESPONSE`: Token from an LLM call made in the 'AGENT_THOUGHT' context, identified as response (e.g., the raw planning output).
1193
- * - `FINAL_SYNTHESIS_LLM_THINKING`: Token from an LLM call made in the 'FINAL_SYNTHESIS' context, identified as thinking.
1194
- * - `FINAL_SYNTHESIS_LLM_RESPONSE`: Token from an LLM call made in the 'FINAL_SYNTHESIS' context, identified as response (part of the final answer to the user).
1536
+ * @since 0.4.11 - Breaking change: New phase-based naming scheme.
1537
+ *
1538
+ * Phase-specific token types:
1539
+ * - `PLANNING_LLM_THINKING`: Thinking token during planning phase.
1540
+ * - `PLANNING_LLM_RESPONSE`: Response token during planning phase.
1541
+ * - `EXECUTION_LLM_THINKING`: Thinking token during execution phase (per-step).
1542
+ * - `EXECUTION_LLM_RESPONSE`: Response token during execution phase.
1543
+ * - `SYNTHESIS_LLM_THINKING`: Thinking token during synthesis phase.
1544
+ * - `SYNTHESIS_LLM_RESPONSE`: Response token during synthesis phase.
1545
+ * - `LLM_THINKING`: Generic fallback when callContext not provided.
1546
+ * - `LLM_RESPONSE`: Generic fallback when callContext not provided.
1195
1547
  *
1196
1548
  * @remarks
1197
1549
  * Not all adapters can reliably distinguish 'LLM_THINKING' vs 'LLM_RESPONSE'.
1198
- * Adapters should prioritize setting the agent context part (`AGENT_THOUGHT_...` or `FINAL_SYNTHESIS_...`) based on `CallOptions.callContext`.
1199
- * If thinking detection is unavailable, adapters should default to `AGENT_THOUGHT_LLM_RESPONSE` or `FINAL_SYNTHESIS_LLM_RESPONSE`.
1200
- * @property {'LLM_THINKING' | 'LLM_RESPONSE' | 'AGENT_THOUGHT_LLM_THINKING' | 'AGENT_THOUGHT_LLM_RESPONSE' | 'FINAL_SYNTHESIS_LLM_THINKING' | 'FINAL_SYNTHESIS_LLM_RESPONSE'} [tokenType]
1550
+ * Adapters should prioritize setting the phase-based token type based on `CallOptions.callContext`.
1551
+ */
1552
+ tokenType?: 'PLANNING_LLM_THINKING' | 'PLANNING_LLM_RESPONSE' | 'EXECUTION_LLM_THINKING' | 'EXECUTION_LLM_RESPONSE' | 'SYNTHESIS_LLM_THINKING' | 'SYNTHESIS_LLM_RESPONSE' | 'LLM_THINKING' | 'LLM_RESPONSE';
1553
+ /**
1554
+ * Phase identification for the agent execution lifecycle.
1555
+ * @since 0.4.11
1556
+ * @property {'planning' | 'execution' | 'synthesis'} [phase]
1557
+ */
1558
+ phase?: 'planning' | 'execution' | 'synthesis';
1559
+ /**
1560
+ * Step ID during execution phase. Links tokens to specific TodoItem being executed.
1561
+ * @since 0.4.11 - Only populated during execution phase.
1562
+ * @property {string} [stepId]
1563
+ */
1564
+ stepId?: string;
1565
+ /**
1566
+ * Step description during execution phase.
1567
+ * @since 0.4.11 - Only populated during execution phase.
1568
+ * @property {string} [stepDescription]
1569
+ */
1570
+ stepDescription?: string;
1571
+ /**
1572
+ * Token emission timestamp (Unix ms).
1573
+ * @since 0.4.11
1574
+ * @property {number} [timestamp]
1201
1575
  */
1202
- tokenType?: 'LLM_THINKING' | 'LLM_RESPONSE' | 'AGENT_THOUGHT_LLM_THINKING' | 'AGENT_THOUGHT_LLM_RESPONSE' | 'FINAL_SYNTHESIS_LLM_THINKING' | 'FINAL_SYNTHESIS_LLM_RESPONSE';
1576
+ timestamp?: number;
1203
1577
  /**
1204
1578
  * The identifier of the conversation thread this event belongs to.
1205
1579
  * @property {string} threadId
@@ -1658,6 +2032,12 @@ interface AgentOptions {
1658
2032
  * @property {Partial<AgentPersona>} [persona]
1659
2033
  */
1660
2034
  persona?: Partial<AgentPersona>;
2035
+ /**
2036
+ * Optional: Configuration for execution phase behavior (TAEF parameters) for this specific call.
2037
+ * Overrides thread and instance-level execution config.
2038
+ * @property {ExecutionConfig} [executionConfig]
2039
+ */
2040
+ executionConfig?: ExecutionConfig;
1661
2041
  }
1662
2042
  /**
1663
2043
  * The final structured response returned by the agent core after processing.
@@ -1788,12 +2168,23 @@ interface CallOptions {
1788
2168
  */
1789
2169
  stream?: boolean;
1790
2170
  /**
1791
- * Provides context for the LLM call, allowing adapters to differentiate
1792
- * between agent-level thoughts and final synthesis calls for token typing.
1793
- * Agent Core MUST provide this.
1794
- * @property {'AGENT_THOUGHT' | 'FINAL_SYNTHESIS' | string} [callContext]
2171
+ * Provides context for the LLM call, identifying which phase of agent execution
2172
+ * is making the request. This determines the tokenType prefix in StreamEvents.
2173
+ *
2174
+ * @since 0.4.11 - Breaking change: Replaced 'AGENT_THOUGHT' and 'FINAL_SYNTHESIS'
2175
+ * with phase-specific values.
2176
+ * @property {'PLANNING_THOUGHTS' | 'EXECUTION_THOUGHTS' | 'SYNTHESIS_THOUGHTS' | string} [callContext]
1795
2177
  */
1796
- callContext?: 'AGENT_THOUGHT' | 'FINAL_SYNTHESIS' | string;
2178
+ callContext?: 'PLANNING_THOUGHTS' | 'EXECUTION_THOUGHTS' | 'SYNTHESIS_THOUGHTS' | string;
2179
+ /**
2180
+ * Step context for execution phase, passed to StreamEvent for step identification.
2181
+ * @since 0.4.11 - Only used during execution phase.
2182
+ * @property {{ stepId: string; stepDescription: string }} [stepContext]
2183
+ */
2184
+ stepContext?: {
2185
+ stepId: string;
2186
+ stepDescription: string;
2187
+ };
1797
2188
  /**
1798
2189
  * An optional callback function invoked when the LLM streams intermediate 'thoughts' or reasoning steps.
1799
2190
  * @deprecated Prefer using StreamEvent with appropriate tokenType for thoughts. Kept for potential transitional compatibility.
@@ -2134,6 +2525,11 @@ interface ArtInstanceConfig {
2134
2525
  * @property {AgentPersona} [persona]
2135
2526
  */
2136
2527
  persona?: AgentPersona;
2528
+ /**
2529
+ * Optional: Configuration for execution phase behavior (TAEF parameters).
2530
+ * @property {ExecutionConfig} [execution]
2531
+ */
2532
+ execution?: ExecutionConfig;
2137
2533
  /**
2138
2534
  * Optional configuration for MCP (Model Context Protocol) manager.
2139
2535
  * Enables connection to external MCP servers for dynamic tool loading.
@@ -2585,6 +2981,40 @@ interface AgentPersona {
2585
2981
  */
2586
2982
  prompts: StageSpecificPrompts;
2587
2983
  }
2984
+ /**
2985
+ * Configuration options for the execution phase of the PES Agent.
2986
+ * Controls TAEF (Tool-Aware Execution Framework) behavior.
2987
+ *
2988
+ * @interface ExecutionConfig
2989
+ */
2990
+ interface ExecutionConfig {
2991
+ /**
2992
+ * Maximum number of LLM iterations per todo item during execution.
2993
+ * Default: 5
2994
+ * @property {number} [maxIterations]
2995
+ */
2996
+ maxIterations?: number;
2997
+ /**
2998
+ * Maximum number of TAEF tool validation retries when required tools are not invoked.
2999
+ * Default: 2
3000
+ * @property {number} [taefMaxRetries]
3001
+ */
3002
+ taefMaxRetries?: number;
3003
+ /**
3004
+ * Maximum character length for tool result serialization in step context.
3005
+ * Higher values preserve more data for the LLM but increase token usage.
3006
+ * Default: 60000 (effectively no practical limit)
3007
+ * @property {number} [toolResultMaxLength]
3008
+ */
3009
+ toolResultMaxLength?: number;
3010
+ /**
3011
+ * Whether to enable A2A (Agent-to-Agent) delegation during execution.
3012
+ * When true, injects the delegate_to_agent tool into execution context.
3013
+ * Default: false
3014
+ * @property {boolean} [enableA2ADelegation]
3015
+ */
3016
+ enableA2ADelegation?: boolean;
3017
+ }
2588
3018
  /**
2589
3019
  * Defines stage-specific system prompts for planning and synthesis.
2590
3020
  *
@@ -2603,6 +3033,13 @@ interface StageSpecificPrompts {
2603
3033
  * @property {string} [synthesis]
2604
3034
  */
2605
3035
  synthesis?: string;
3036
+ /**
3037
+ * Custom system prompt template for tool execution steps.
3038
+ * If provided, overrides the default execution prompt.
3039
+ * Supports variable interpolation: ${item.description}, ${completedItemsContext}, etc.
3040
+ * @property {string} [execution]
3041
+ */
3042
+ execution?: string;
2606
3043
  }
2607
3044
 
2608
3045
  /**
@@ -2856,7 +3293,7 @@ interface IAgentCore {
2856
3293
  /**
2857
3294
  * Interface for the component responsible for interacting with LLMs.
2858
3295
  */
2859
- interface ReasoningEngine {
3296
+ interface ReasoningEngine$1 {
2860
3297
  /**
2861
3298
  * Executes a call to the configured Large Language Model (LLM).
2862
3299
  * This method is typically implemented by a specific `ProviderAdapter`.
@@ -2876,7 +3313,7 @@ interface ReasoningEngine {
2876
3313
  * Resolves the final system prompt from base + instance/thread/call overrides
2877
3314
  * using tag+variables and merge strategies.
2878
3315
  */
2879
- interface SystemPromptResolver {
3316
+ interface SystemPromptResolver$1 {
2880
3317
  resolve(input: {
2881
3318
  base: string;
2882
3319
  instance?: string | SystemPromptOverride;
@@ -2887,7 +3324,7 @@ interface SystemPromptResolver {
2887
3324
  /**
2888
3325
  * Interface for parsing structured output from LLM responses.
2889
3326
  */
2890
- interface OutputParser {
3327
+ interface OutputParser$1 {
2891
3328
  /**
2892
3329
  * Parses the raw string output from the planning LLM call to extract structured information.
2893
3330
  * Implementations should be robust to variations in LLM output formatting.
@@ -2935,7 +3372,7 @@ interface OutputParser {
2935
3372
  * Base interface for LLM Provider Adapters, extending the core ReasoningEngine.
2936
3373
  * Implementations will handle provider-specific API calls, authentication, etc.
2937
3374
  */
2938
- interface ProviderAdapter extends ReasoningEngine {
3375
+ interface ProviderAdapter extends ReasoningEngine$1 {
2939
3376
  /** The unique identifier name for this provider (e.g., 'openai', 'anthropic'). */
2940
3377
  readonly providerName: string;
2941
3378
  /** Optional: Method for graceful shutdown */
@@ -3846,9 +4283,9 @@ interface PESAgentDependencies {
3846
4283
  /** Registry for available tools. */
3847
4284
  toolRegistry: ToolRegistry$1;
3848
4285
  /** Handles interaction with the LLM provider. */
3849
- reasoningEngine: ReasoningEngine;
4286
+ reasoningEngine: ReasoningEngine$1;
3850
4287
  /** Parses LLM responses. */
3851
- outputParser: OutputParser;
4288
+ outputParser: OutputParser$1;
3852
4289
  /** Records agent execution observations. */
3853
4290
  observationManager: ObservationManager;
3854
4291
  /** Orchestrates tool execution. */
@@ -3862,7 +4299,7 @@ interface PESAgentDependencies {
3862
4299
  /** Service for delegating A2A tasks. */
3863
4300
  taskDelegationService?: TaskDelegationService | null;
3864
4301
  /** Resolver for standardized system prompt composition. */
3865
- systemPromptResolver: SystemPromptResolver;
4302
+ systemPromptResolver: SystemPromptResolver$1;
3866
4303
  /** Optional: Defines the default identity and high-level guidance for the agent. */
3867
4304
  persona?: AgentPersona;
3868
4305
  }
@@ -3876,6 +4313,13 @@ declare class PESAgent implements IAgentCore {
3876
4313
  constructor(dependencies: PESAgentDependencies);
3877
4314
  process(props: AgentProps): Promise<AgentFinalResponse>;
3878
4315
  private _saveState;
4316
+ /**
4317
+ * Issue #2 fix: Persists execution step results to ConversationManager for follow-up query context.
4318
+ * This ensures that completed step information is available in conversation history.
4319
+ *
4320
+ * @since 0.4.11
4321
+ */
4322
+ private _persistExecutionSummary;
3879
4323
  private _recordPlanObservations;
3880
4324
  private _performPlanning;
3881
4325
  private _performPlanRefinement;
@@ -3884,6 +4328,7 @@ declare class PESAgent implements IAgentCore {
3884
4328
  /**
3885
4329
  * Builds execution prompt for TOOL-type steps.
3886
4330
  * Emphasizes tool invocation and explicitly names required tools.
4331
+ * Includes Data Flow Directive to guide LLM in extracting data from previous results.
3887
4332
  */
3888
4333
  private _buildToolStepPrompt;
3889
4334
  /**
@@ -4499,9 +4944,6 @@ declare class OpenRouterAdapter implements ProviderAdapter {
4499
4944
  private translateToOpenAI;
4500
4945
  }
4501
4946
 
4502
- /**
4503
- * Configuration options required for the `DeepSeekAdapter`.
4504
- */
4505
4947
  interface DeepSeekAdapterOptions {
4506
4948
  /** Your DeepSeek API key. Handle securely. */
4507
4949
  apiKey: string;
@@ -5322,35 +5764,730 @@ declare class ToolRegistry implements ToolRegistry$1 {
5322
5764
  }
5323
5765
 
5324
5766
  /**
5325
- * Manages the lifecycle and access to multiple ProviderAdapter implementations.
5767
+ * @module systems/reasoning/ProviderManagerImpl
5768
+ *
5769
+ * This module provides the default implementation of the IProviderManager interface.
5770
+ * It manages the lifecycle of provider adapters, handles concurrency limits,
5771
+ * supports both API-based and local providers, and implements intelligent pooling
5772
+ * and queueing strategies.
5773
+ *
5774
+ * Key features:
5775
+ * - Multi-provider support with dynamic adapter registration
5776
+ * - Concurrency limiting per provider (configurable)
5777
+ * - Instance pooling and reuse for API-based providers
5778
+ * - Singleton pattern for local providers (e.g., Ollama)
5779
+ * - Request queuing for API providers when limits are reached
5780
+ * - Automatic idle timeout and eviction for API instances
5781
+ * - Safe error handling with proper cleanup
5782
+ *
5783
+ * @see IProviderManager for the interface definition
5784
+ * @see AvailableProviderEntry for provider registration
5785
+ * @see RuntimeProviderConfig for runtime provider configuration
5786
+ * @see ManagedAdapterAccessor for managed adapter access
5787
+ */
5788
+
5789
+ /**
5790
+ * Default implementation of the IProviderManager interface.
5791
+ *
5792
+ * @remarks
5793
+ * This class provides intelligent management of LLM provider adapters with the following capabilities:
5794
+ *
5795
+ * **Lifecycle Management:**
5796
+ * - Creates new adapter instances on demand
5797
+ * - Reuses idle instances when possible
5798
+ * - Properly shuts down instances when they're no longer needed
5799
+ *
5800
+ * **Concurrency Control:**
5801
+ * - Enforces maximum parallel API calls per provider (configurable)
5802
+ * - Implements a queue-based system for requests exceeding limits
5803
+ * - Prevents resource exhaustion by queuing when all instances are busy
5804
+ *
5805
+ * **Provider Types:**
5806
+ * - API-based providers (OpenAI, Anthropic, etc.):
5807
+ * - Multiple instances can be created and pooled
5808
+ * - Instances have an idle timeout after which they're evicted
5809
+ * - Supports concurrent requests up to the configured limit
5810
+ *
5811
+ * - Local providers (Ollama, local LLMs):
5812
+ * - Enforced singleton pattern (only one instance can be active)
5813
+ * - Prevents multiple simultaneous requests to the same local instance
5814
+ * - Throws specific errors if conflicting requests are made
5815
+ *
5816
+ * **Request Queuing:**
5817
+ * - When an API provider's limit is reached, new requests are queued
5818
+ * - Requests are processed in FIFO (First-In-First-Out) order
5819
+ * - When an instance becomes available (released), queued requests are served
5820
+ * - Prevents request loss and ensures fair resource allocation
5821
+ *
5822
+ * **Error Handling:**
5823
+ * - Throws specific errors for provider-related failures
5824
+ * - Includes UnknownProviderError for unregistered providers
5825
+ * - Includes LocalProviderConflictError for conflicting local requests
5826
+ * - Includes LocalInstanceBusyError for busy local instances
5827
+ * - Ensures proper cleanup even when errors occur
5828
+ *
5829
+ * **Security:**
5830
+ * - Never includes secrets (API keys) in signature strings for logging
5831
+ * - Sanitizes configuration signatures to prevent sensitive data leakage
5832
+ *
5833
+ * Usage Example:
5834
+ * ```typescript
5835
+ * const manager = new ProviderManagerImpl({
5836
+ * availableProviders: [
5837
+ * { name: 'openai', adapter: OpenAIAdapter, baseOptions: { apiKey: 'sk-...' } },
5838
+ * { name: 'ollama', adapter: OllamaAdapter, isLocal: true }
5839
+ * ],
5840
+ * maxParallelApiInstancesPerProvider: 3,
5841
+ * apiInstanceIdleTimeoutSeconds: 300
5842
+ * });
5843
+ *
5844
+ * // Get an adapter
5845
+ * const accessor = await manager.getAdapter({
5846
+ * providerName: 'openai',
5847
+ * modelId: 'gpt-4',
5848
+ * adapterOptions: { temperature: 0.7 }
5849
+ * });
5850
+ *
5851
+ * // Use the adapter
5852
+ * const stream = await accessor.adapter.call(prompt, options);
5853
+ * for await (const event of stream) { ... }
5854
+ *
5855
+ * // Release the adapter (important!)
5856
+ * accessor.release();
5857
+ * ```
5858
+ *
5859
+ * @class ProviderManagerImpl
5860
+ * @implements IProviderManager
5326
5861
  */
5327
5862
  declare class ProviderManagerImpl implements IProviderManager {
5863
+ /**
5864
+ * Map of registered provider configurations.
5865
+ * Keys are provider names (e.g., 'openai', 'anthropic', 'ollama_local').
5866
+ * @private
5867
+ */
5328
5868
  private availableProviders;
5869
+ /**
5870
+ * Maximum number of concurrent active instances per API-based provider.
5871
+ * Default: 5
5872
+ * @private
5873
+ */
5329
5874
  private maxParallelApiInstancesPerProvider;
5875
+ /**
5876
+ * Timeout in milliseconds for an API instance before it's evicted.
5877
+ * Default: 300,000ms (5 minutes)
5878
+ * @private
5879
+ */
5330
5880
  private apiInstanceIdleTimeoutMs;
5881
+ /**
5882
+ * Map of currently managed adapter instances.
5883
+ * Keys are configuration signatures, values are instance metadata.
5884
+ * @private
5885
+ */
5331
5886
  private managedInstances;
5887
+ /**
5888
+ * Queue of pending requests that couldn't be immediately fulfilled.
5889
+ * @private
5890
+ */
5332
5891
  private requestQueue;
5892
+ /**
5893
+ * Creates a new ProviderManagerImpl instance.
5894
+ *
5895
+ * @param config - Configuration for the provider manager.
5896
+ *
5897
+ * @remarks
5898
+ * The configuration must include:
5899
+ * - `availableProviders`: Array of provider entries with adapter classes
5900
+ * - `maxParallelApiInstancesPerProvider`: Maximum concurrent API calls per provider (optional)
5901
+ * - `apiInstanceIdleTimeoutSeconds`: Idle timeout for API instances in seconds (optional)
5902
+ */
5333
5903
  constructor(config: ProviderManagerConfig);
5334
5904
  /**
5335
- * Generates a stable configuration signature for caching.
5336
- * @param config The runtime provider configuration.
5337
- * @returns A string signature.
5905
+ * Generates a stable configuration signature for caching and lookup.
5906
+ *
5907
+ * @remarks
5908
+ * The signature is used as the key in the managedInstances map.
5909
+ * It includes provider name and model ID, allowing different instances
5910
+ * of the same provider with different models to coexist.
5911
+ *
5912
+ * Security Note: Never includes sensitive data like API keys.
5913
+ * Keys are replaced with '***' before being used in the signature.
5914
+ *
5915
+ * @param config - The runtime provider configuration.
5916
+ * @returns A stable string signature uniquely identifying this configuration.
5917
+ *
5918
+ * @private
5338
5919
  */
5339
5920
  private _getConfigSignature;
5921
+ /**
5922
+ * Returns an array of all registered provider names.
5923
+ *
5924
+ * @returns Array of provider name strings.
5925
+ */
5340
5926
  getAvailableProviders(): string[];
5927
+ /**
5928
+ * Gets a managed adapter instance based on runtime configuration.
5929
+ *
5930
+ * @remarks
5931
+ * This method implements sophisticated adapter management:
5932
+ *
5933
+ * 1. **Cache Check**: First checks if an existing instance matches the requested configuration
5934
+ * - If found and idle, reuses it immediately
5935
+ * - Updates lastUsedTimestamp for idle timeout tracking
5936
+ * - Clears any existing idle timer
5937
+ *
5938
+ * 2. **Local Provider Constraints**: For local providers (isLocal: true):
5939
+ * - Only one instance of a local provider can be active at a time
5940
+ * - If requesting a different model of an active local instance, throws LocalProviderConflictError
5941
+ * - If the same local instance is already active and busy, throws LocalInstanceBusyError
5942
+ * - This prevents concurrent access issues with local LLMs
5943
+ *
5944
+ * 3. **API Provider Concurrency**:
5945
+ * - Counts currently active instances for this provider
5946
+ * - If under maxParallelApiInstancesPerProvider, creates new instance
5947
+ * - If at the limit, queues the request instead of failing
5948
+ * - Ensures fair resource allocation and prevents request loss
5949
+ *
5950
+ * 4. **Instance Creation**: Creates new instances using provider's adapter class
5951
+ * - Merges base options from provider entry with runtime adapter options
5952
+ * - Provider-specific options (API keys) are merged in
5953
+ * - Adapter instantiation errors are wrapped in AdapterInstantiationError
5954
+ *
5955
+ * 5. **Accessor Return**: Returns an object with:
5956
+ * - adapter: The ready-to-use ProviderAdapter instance
5957
+ * - release: Function to release the adapter back to the manager
5958
+ *
5959
+ * @param config - The runtime provider configuration specifying which provider and model to use.
5960
+ *
5961
+ * @returns A promise resolving to a ManagedAdapterAccessor containing the adapter and release function.
5962
+ *
5963
+ * @throws {UnknownProviderError} If the provider name is not registered.
5964
+ * @throws {LocalProviderConflictError} If requesting a different model of an active local provider.
5965
+ * @throws {LocalInstanceBusyError} If the requested local instance is currently busy.
5966
+ *
5967
+ * @example
5968
+ * ```typescript
5969
+ * // Request with a pooled instance
5970
+ * const accessor = await manager.getAdapter({
5971
+ * providerName: 'openai',
5972
+ * modelId: 'gpt-4',
5973
+ * adapterOptions: { temperature: 0.7 }
5974
+ * });
5975
+ * const stream = await accessor.adapter.call(prompt, options);
5976
+ * for await (const event of stream) { ... }
5977
+ * accessor.release();
5978
+ *
5979
+ * // Request that will be queued if limit reached
5980
+ * const accessor2 = await manager.getAdapter({
5981
+ * providerName: 'openai',
5982
+ * modelId: 'gpt-4'
5983
+ * });
5984
+ * // ... request completes ...
5985
+ * ```
5986
+ */
5341
5987
  getAdapter(config: RuntimeProviderConfig): Promise<ManagedAdapterAccessor>;
5342
5988
  /**
5343
5989
  * Internal method to release an adapter instance back to the manager.
5344
- * @param configSignature The signature of the instance to release.
5990
+ *
5991
+ * @param configSignature - The signature of the instance to release.
5992
+ *
5993
+ * @remarks
5994
+ * This method:
5995
+ * 1. Marks the instance as 'idle'
5996
+ * 2. Clears any idle timer
5997
+ * 3. Clears lastUsedTimestamp
5998
+ * 4. Does NOT delete the instance from managedInstances
5999
+ * 5. Checks request queue for pending requests that can now be fulfilled
6000
+ *
6001
+ * The instance remains in the pool for future reuse.
6002
+ *
6003
+ * @private
5345
6004
  */
5346
6005
  private _releaseAdapter;
5347
6006
  /**
5348
6007
  * Internal method to evict an instance from the manager.
5349
- * @param configSignature The signature of the instance to evict.
6008
+ *
6009
+ * @param configSignature - The signature of the instance to evict.
6010
+ *
6011
+ * @remarks
6012
+ * This method:
6013
+ * 1. Calls the adapter's shutdown method if available
6014
+ * 2. Removes the instance from managedInstances
6015
+ * 3. Clears the idle timer if present
6016
+ *
6017
+ * Eviction can happen due to:
6018
+ * - Idle timeout (for API instances)
6019
+ * - Manager shutdown (not implemented yet but reserved)
6020
+ *
6021
+ * @private
5350
6022
  */
5351
6023
  private _evictInstance;
5352
6024
  }
5353
6025
 
6026
+ /**
6027
+ * @module systems/reasoning/ReasoningEngine
6028
+ *
6029
+ * This module provides the default implementation of the ReasoningEngine interface,
6030
+ * which serves as the primary abstraction for interacting with Large Language Models (LLMs)
6031
+ * in the ART framework.
6032
+ *
6033
+ * Key features:
6034
+ * - Multi-provider support via IProviderManager
6035
+ * - Automatic adapter lifecycle management (acquisition, pooling, release)
6036
+ * - Streaming response support with proper resource cleanup
6037
+ * - Runtime provider selection based on thread/call configuration
6038
+ *
6039
+ * @see IReasoningEngine for the interface definition
6040
+ * @see ProviderAdapter for adapter interface to different LLM providers
6041
+ * @see IProviderManager for provider management interface
6042
+ */
6043
+
6044
+ /**
6045
+ * Default implementation of the ReasoningEngine interface.
6046
+ *
6047
+ * This class serves as the central point for all LLM interactions within the ART framework.
6048
+ * It abstracts away the specifics of dealing with different LLM providers (OpenAI, Anthropic,
6049
+ * Gemini, etc.) by delegating to provider-specific ProviderAdapter instances obtained from the
6050
+ * IProviderManager.
6051
+ *
6052
+ * Key responsibilities:
6053
+ * 1. Dynamic Provider Selection: Obtains the appropriate ProviderAdapter instance based on
6054
+ * runtime configuration (RuntimeProviderConfig) specified in CallOptions. This allows different
6055
+ * threads or calls to use different LLM providers or models.
6056
+ *
6057
+ * 2. Resource Management: Ensures that adapter instances are properly released back to the
6058
+ * IProviderManager after use, enabling connection pooling, reuse, and proper cleanup.
6059
+ * This is critical for maintaining performance and preventing resource leaks.
6060
+ *
6061
+ * 3. Streaming Support: Returns an AsyncIterable that yields tokens, metadata, and
6062
+ * lifecycle events as they arrive from the LLM provider. The implementation wraps the
6063
+ * adapter's stream to ensure proper resource cleanup even if iteration is aborted or errors occur.
6064
+ *
6065
+ * 4. Error Handling: Transforms provider-specific errors into a consistent interface and
6066
+ * ensures adapters are released even when errors occur during call setup or stream processing.
6067
+ *
6068
+ * @class ReasoningEngine
6069
+ * @implements IReasoningEngine
6070
+ */
6071
+ declare class ReasoningEngine implements ReasoningEngine$1 {
6072
+ /**
6073
+ * The provider manager instance used to obtain adapter instances at runtime.
6074
+ * This manager handles adapter instantiation, pooling, concurrency limits, and lifecycle management.
6075
+ * @private
6076
+ */
6077
+ private providerManager;
6078
+ /**
6079
+ * Creates a new ReasoningEngine instance.
6080
+ *
6081
+ * @param providerManager - The IProviderManager instance responsible for managing provider adapters.
6082
+ * This manager must be pre-configured with available providers and their settings.
6083
+ *
6084
+ * @remarks
6085
+ * The engine does not create adapters directly but relies on the provider manager to supply
6086
+ * them on demand. This enables centralized management of provider credentials, connection pooling,
6087
+ * and concurrency control.
6088
+ */
6089
+ constructor(providerManager: IProviderManager);
6090
+ /**
6091
+ * Executes an LLM call using a dynamically selected provider adapter.
6092
+ *
6093
+ * @remarks
6094
+ * This method orchestrates the entire LLM call lifecycle:
6095
+ *
6096
+ * 1. Provider Configuration Validation: Ensures that providerConfig is present in CallOptions.
6097
+ * This is required for the multi-provider architecture.
6098
+ *
6099
+ * 2. Adapter Acquisition: Requests a ManagedAdapterAccessor from the IProviderManager.
6100
+ * The manager handles:
6101
+ * - Instantiating new adapters if needed
6102
+ * - Reusing existing adapters from the pool
6103
+ * - Enforcing concurrency limits (e.g., max parallel API calls per provider)
6104
+ * - Managing singleton behavior for local providers (e.g., Ollama)
6105
+ * - Queueing requests when limits are reached
6106
+ *
6107
+ * 3. Call Delegation: Delegates the actual LLM call to the obtained adapter's call method.
6108
+ * The adapter is responsible for:
6109
+ * - Formatting the prompt for the specific provider API
6110
+ * - Making the HTTP request
6111
+ * - Parsing provider responses into standard StreamEvent objects
6112
+ * - Handling provider-specific streaming logic
6113
+ *
6114
+ * 4. Resource Cleanup: Wraps the adapter's stream in a generator that automatically calls
6115
+ * accessor.release() when the stream is consumed, errors occur, or iteration is aborted.
6116
+ * This ensures adapters are always returned to the pool, preventing resource leaks.
6117
+ *
6118
+ * 5. Error Handling: Catches and logs any errors during adapter acquisition or call execution,
6119
+ * ensuring the adapter is released before re-throwing the error to the caller.
6120
+ *
6121
+ * @param prompt - The prompt to send to the LLM. This is the FormattedPrompt type,
6122
+ * which represents an array of standardized messages (ArtStandardMessage[]).
6123
+ * The provider adapter is responsible for translating this to the specific
6124
+ * API format required by the underlying LLM provider.
6125
+ *
6126
+ * @param options - Configuration options for this specific LLM call. Must include:
6127
+ * - threadId (string): Required for identifying the thread and loading its configuration
6128
+ * - providerConfig (RuntimeProviderConfig): Specifies which provider and model to use
6129
+ * - traceId (string, optional): For distributed tracing and debugging
6130
+ * - userId (string, optional): For user-specific configuration or logging
6131
+ * - sessionId (string, optional): For multi-tab/session UI scenarios
6132
+ * - stream (boolean, optional): Whether to request streaming responses (default: false)
6133
+ * - callContext (string, optional): Context for the call (e.g., 'AGENT_THOUGHT', 'FINAL_SYNTHESIS')
6134
+ * - Additional provider-specific parameters (e.g., temperature, max_tokens)
6135
+ *
6136
+ * @returns A promise resolving to an AsyncIterable<StreamEvent>. The iterable yields events as they arrive:
6137
+ * - TOKEN: Individual text tokens from the LLM
6138
+ * - METADATA: Metadata about the call (token counts, timing, stop reason)
6139
+ * - END: Signal that the stream has completed successfully
6140
+ * - ERROR: Indicates an error occurred during streaming
6141
+ *
6142
+ * The returned iterable is wrapped to ensure proper adapter cleanup when iteration completes
6143
+ * or is interrupted.
6144
+ *
6145
+ * @throws {Error} Throws various errors that may occur:
6146
+ * - Missing "providerConfig" in CallOptions: If provider configuration is not supplied
6147
+ * - Provider-specific errors from adapter acquisition or execution (e.g., authentication failures, rate limits)
6148
+ * - Network errors or timeouts
6149
+ */
6150
+ call(prompt: FormattedPrompt, options: CallOptions): Promise<AsyncIterable<StreamEvent>>;
6151
+ }
6152
+
6153
+ /**
6154
+ * @module systems/reasoning/OutputParser
6155
+ *
6156
+ * This module provides implementation for parsing structured output from LLM responses
6157
+ * in the ART framework. It handles planning, execution, and synthesis outputs.
6158
+ *
6159
+ * Key features:
6160
+ * - Multi-format parsing support (JSON with markers, markdown code blocks, brace matching)
6161
+ * - XML tag extraction for thoughts (e.g., <think> tags)
6162
+ * - Zod schema validation for structured data
6163
+ * - Robust error handling and fallback parsing
6164
+ *
6165
+ * @see IOutputParser for interface definition
6166
+ * @see ParsedToolCall for parsed tool call structure
6167
+ * @see TodoItem for parsed todo item structure
6168
+ * @see ExecutionOutput for execution output structure
6169
+ */
6170
+
6171
+ /**
6172
+ * Default implementation of the IOutputParser interface.
6173
+ *
6174
+ * @remarks
6175
+ * This class provides robust parsing capabilities for structured output from LLMs.
6176
+ * It is designed to handle variations in LLM output formatting across different providers
6177
+ * and models. The parser uses a multi-tier strategy for extracting structured data:
6178
+ *
6179
+ * 1. XML Tag Extraction: Extracts content from XML-like tags (e.g., <think>)
6180
+ * using the XmlMatcher utility. This separates "thoughts" or "reasoning" from
6181
+ * the main structured output.
6182
+ *
6183
+ * 2. JSON Extraction: Attempts multiple strategies to find and parse JSON:
6184
+ * - Priority 1: Explicit JSON markers (---JSON_OUTPUT_START--- ... ---JSON_OUTPUT_END---)
6185
+ * - Priority 2: Markdown code blocks (```json ... ``` or ``` ... ```)
6186
+ * - Priority 3: Strip markdown fences and attempt direct parsing
6187
+ * - Priority 4: Find JSON object by brace matching for mixed content
6188
+ *
6189
+ * 3. Schema Validation: Uses Zod schemas to validate parsed structures:
6190
+ * - ParsedToolCall validation ensures tool calls have required fields
6191
+ * - TodoItem validation ensures todo items conform to expected structure
6192
+ *
6193
+ * 4. Fallback Parsing: If JSON extraction fails, attempts to extract information
6194
+ * from labeled sections (e.g., "Title: ...", "Intent: ...", "Plan: ...")
6195
+ *
6196
+ * The parser is resilient to:
6197
+ * - Malformed or incomplete XML tags
6198
+ * - Missing or malformed JSON
6199
+ * - Mixed content (text + JSON)
6200
+ * - Provider-specific formatting differences
6201
+ *
6202
+ * @class OutputParser
6203
+ * @implements IOutputParser
6204
+ */
6205
+ declare class OutputParser implements OutputParser$1 {
6206
+ /**
6207
+ * Helper method for parsing JSON from a raw string with multiple fallback strategies.
6208
+ *
6209
+ * @remarks
6210
+ * This method implements a tiered approach to finding and parsing JSON:
6211
+ *
6212
+ * 1. **Explicit Markers**: Looks for ---JSON_OUTPUT_START--- and ---JSON_OUTPUT_END---
6213
+ * markers. This is the most reliable method as markers are unambiguous.
6214
+ *
6215
+ * 2. **Markdown Code Blocks**: Looks for fenced code blocks with ```json, ```JSON,
6216
+ * or just ``` delimiters. Handles case-insensitive matching.
6217
+ *
6218
+ * 3. **Fence Stripping**: If regex didn't catch markdown blocks (e.g., malformed),
6219
+ * strips leading ``` and trailing ``` markers and attempts parsing.
6220
+ *
6221
+ * 4. **Brace Matching**: As a fallback for mixed content, finds the first
6222
+ * { and last } characters and extracts the content between them.
6223
+ *
6224
+ * The method is resilient to:
6225
+ * - Non-JSON content outside of delimiters
6226
+ * - Malformed JSON (returns null)
6227
+ * - Circular references (though less likely in LLM output)
6228
+ * - Non-serializable values (functions, symbols)
6229
+ *
6230
+ * @param raw - The raw string that may contain JSON.
6231
+ * @returns The parsed JavaScript object if valid JSON is found, null otherwise.
6232
+ *
6233
+ * @private
6234
+ */
6235
+ private tryParseJson;
6236
+ /**
6237
+ * Parses the raw string output from the planning LLM call.
6238
+ *
6239
+ * @remarks
6240
+ * The planning phase generates structured output including:
6241
+ * - title: A concise thread title (<= 10 words)
6242
+ * - intent: A summary of the user's goal
6243
+ * - plan: A human-readable description of the approach
6244
+ * - toolCalls: Structured tool call requests
6245
+ * - todoList: A list of TodoItem objects representing the execution plan
6246
+ * - thoughts: Content extracted from <think> XML tags
6247
+ *
6248
+ * This method:
6249
+ * 1. Extracts thoughts from <think> tags using XmlMatcher
6250
+ * 2. Attempts to parse the remaining content as JSON
6251
+ * 3. Validates toolCalls against Zod schema
6252
+ * 4. Validates todoList against Zod schema
6253
+ * 5. Falls back to section-based parsing if JSON fails
6254
+ *
6255
+ * The fallback section-based parsing looks for labeled sections like:
6256
+ * "Title: ...", "Intent: ...", "Plan: ..." using regex patterns.
6257
+ *
6258
+ * @param output - The raw string response from the planning LLM.
6259
+ *
6260
+ * @returns A promise resolving to an object containing:
6261
+ * - title (string, optional): Concise thread title
6262
+ * - intent (string, optional): User's goal summary
6263
+ * - plan (string, optional): Human-readable plan description
6264
+ * - toolCalls (ParsedToolCall[], optional): Parsed tool call requests
6265
+ * - todoList (TodoItem[], optional): List of execution steps
6266
+ * - thoughts (string, optional): Extracted from <think> tags
6267
+ *
6268
+ * @throws Never throws; errors are handled gracefully with empty results.
6269
+ */
6270
+ parsePlanningOutput(output: string): Promise<{
6271
+ title?: string;
6272
+ intent?: string;
6273
+ plan?: string;
6274
+ toolCalls?: ParsedToolCall[];
6275
+ thoughts?: string;
6276
+ todoList?: TodoItem[];
6277
+ }>;
6278
+ /**
6279
+ * Parses the raw string output from an execution LLM call (per todo item).
6280
+ *
6281
+ * @remarks
6282
+ * The execution phase generates output that may include:
6283
+ * - thoughts: Reasoning extracted from <think> tags
6284
+ * - toolCalls: Structured tool call requests for the current step
6285
+ * - nextStepDecision: Decision on how to proceed (continue, wait, complete_item, update_plan)
6286
+ * - updatedPlan: Modifications to the execution plan
6287
+ * - content: Freeform text response
6288
+ *
6289
+ * This method:
6290
+ * 1. Extracts thoughts from <think> tags using XmlMatcher
6291
+ * 2. Attempts to parse the remaining content as JSON
6292
+ * 3. Validates toolCalls against Zod schema
6293
+ * 4. Extracts structured fields if JSON parsing succeeds
6294
+ * 5. Falls back to treating everything as freeform content if JSON fails
6295
+ *
6296
+ * The nextStepDecision values guide the TAEF execution:
6297
+ * - 'continue': Proceed with next iteration
6298
+ * - 'wait': Pause execution (rare in execution phase)
6299
+ * - 'complete_item': Mark current todo item as complete
6300
+ * - 'update_plan': Modify the execution plan
6301
+ *
6302
+ * @param output - The raw string response from the execution LLM.
6303
+ *
6304
+ * @returns A promise resolving to an ExecutionOutput object containing:
6305
+ * - thoughts (string, optional): Extracted from <think> tags
6306
+ * - toolCalls (ParsedToolCall[], optional): Parsed tool call requests
6307
+ * - nextStepDecision (string, optional): How to proceed
6308
+ * - updatedPlan (object, optional): Plan modifications
6309
+ * - content (string, optional): Freeform text response
6310
+ *
6311
+ * @throws Never throws; errors are handled gracefully with empty results.
6312
+ */
6313
+ parseExecutionOutput(output: string): Promise<ExecutionOutput>;
6314
+ /**
6315
+ * Parses the raw string output from the synthesis LLM call.
6316
+ *
6317
+ * @remarks
6318
+ * The synthesis phase generates the final, user-facing response.
6319
+ * This method typically just trims the output, as synthesis output
6320
+ * is usually freeform text without structured components.
6321
+ *
6322
+ * Future enhancements might include:
6323
+ * - Removing extraneous tags or markers
6324
+ * - Formatting cleanup
6325
+ * - Extracting specific sections if needed
6326
+ *
6327
+ * @param output - The raw string response from the synthesis LLM.
6328
+ *
6329
+ * @returns A promise resolving to the cleaned, final response string.
6330
+ *
6331
+ * @throws Never throws; always returns at least an empty string.
6332
+ */
6333
+ parseSynthesisOutput(output: string): Promise<string>;
6334
+ }
6335
+
6336
+ /**
6337
+ * Default implementation of ISystemPromptResolver interface.
6338
+ *
6339
+ * @remarks
6340
+ * This class manages the resolution and merging of system prompts across multiple levels:
6341
+ * 1. Base prompt - The fundamental system instruction from agent persona or framework defaults
6342
+ * 2. Instance-level override - Global configuration applied to all threads in an ART instance
6343
+ * 3. Thread-level override - Configuration specific to a single conversation thread
6344
+ * 4. Call-level override - Configuration for a specific LLM call
6345
+ *
6346
+ * Each level can provide either:
6347
+ * - A preset tag that references a template from SystemPromptsRegistry
6348
+ * - Freeform content that is directly used
6349
+ *
6350
+ * The resolution process:
6351
+ * 1. Starts with the base prompt
6352
+ * 2. Applies instance-level override (if provided)
6353
+ * 3. Applies thread-level override (if provided)
6354
+ * 4. Applies call-level override (if provided)
6355
+ *
6356
+ * At each level, the override is:
6357
+ * - Rendered from a template if a tag is specified (with variable substitution)
6358
+ * - Used directly if freeform content is provided
6359
+ * - Applied using the specified merge strategy (append or prepend)
6360
+ *
6361
+ * Template rendering supports:
6362
+ * - Simple variable interpolation: {{variableName}}
6363
+ * - Prompt fragment references: {{fragment:name}}
6364
+ *
6365
+ * @example
6366
+ * ```typescript
6367
+ * const resolver = new SystemPromptResolver({
6368
+ * specs: {
6369
+ * 'default': {
6370
+ * template: 'You are {{name}}. Be {{tone}}.',
6371
+ * defaultVariables: { name: 'AI Assistant', tone: 'helpful' }
6372
+ * },
6373
+ * 'expert': {
6374
+ * template: 'You are an expert in {{topic}}.',
6375
+ * mergeStrategy: 'prepend'
6376
+ * }
6377
+ * },
6378
+ * defaultTag: 'default'
6379
+ * });
6380
+ *
6381
+ * const result = await resolver.resolve({
6382
+ * base: 'System: You are helpful.',
6383
+ * instance: { tag: 'expert', variables: { topic: 'physics' } },
6384
+ * thread: { tag: 'default', strategy: 'append' }
6385
+ * }, 'trace-123');
6386
+ * // Result combines: base + expert (prepended) + default (appended)
6387
+ * ```
6388
+ *
6389
+ * @class SystemPromptResolver
6390
+ * @implements ISystemPromptResolver
6391
+ */
6392
+ declare class SystemPromptResolver implements SystemPromptResolver$1 {
6393
+ /**
6394
+ * Optional registry of system prompt presets (templates) that can be referenced by tag.
6395
+ * @private
6396
+ * @type {SystemPromptsRegistry | undefined}
6397
+ */
6398
+ private readonly registry?;
6399
+ /**
6400
+ * Creates a new SystemPromptResolver instance.
6401
+ *
6402
+ * @param registry - Optional registry of prompt preset templates indexed by tag name.
6403
+ * If provided, overrides can reference templates by tag name.
6404
+ */
6405
+ constructor(registry?: SystemPromptsRegistry);
6406
+ /**
6407
+ * Resolves the final system prompt by applying overrides in precedence order.
6408
+ *
6409
+ * @remarks
6410
+ * The resolution process follows this precedence hierarchy (highest to lowest):
6411
+ * 1. Call-level override (immediate, most specific)
6412
+ * 2. Thread-level override (conversation-specific)
6413
+ * 3. Instance-level override (instance-wide)
6414
+ * 4. Base prompt (default)
6415
+ *
6416
+ * For each override level:
6417
+ * - If a tag is provided and exists in registry: Render the template
6418
+ * - If freeform content is provided: Use it directly
6419
+ * - Apply using the specified merge strategy (defaults to 'append')
6420
+ * - Variables for template rendering come from defaultVariables merged with provided variables
6421
+ *
6422
+ * Template variable substitution:
6423
+ * - Variables are wrapped in double braces: {{variableName}}
6424
+ * - Supports fragment references: {{fragment:name}} (for PromptManager integration)
6425
+ * - Missing variables render as empty strings
6426
+ *
6427
+ * Merge strategies:
6428
+ * - 'append': Adds content to the end of existing prompt (default)
6429
+ * - 'prepend': Adds content to the beginning of existing prompt
6430
+ *
6431
+ * Note: 'replace' strategy is intentionally unsupported to prevent custom prompts
6432
+ * from overriding framework-required structural contracts.
6433
+ *
6434
+ * @param input - Object containing the base prompt and optional overrides at each level.
6435
+ * - base (string): The fundamental system prompt (required)
6436
+ * - instance (string | SystemPromptOverride): Instance-level override
6437
+ * - thread (string | SystemPromptOverride): Thread-level override
6438
+ * - call (string | SystemPromptOverride): Call-level override
6439
+ * @param traceId - Optional trace identifier for logging and debugging purposes.
6440
+ *
6441
+ * @returns A promise resolving to the final, resolved system prompt string.
6442
+ *
6443
+ * @example
6444
+ * ```typescript
6445
+ * const result = await resolver.resolve({
6446
+ * base: 'You are a helpful AI.',
6447
+ * instance: {
6448
+ * tag: 'technical',
6449
+ * variables: { specialization: 'web development' }
6450
+ * },
6451
+ * thread: { content: 'Be concise in your responses.' }
6452
+ * }, 'trace-123');
6453
+ * ```
6454
+ */
6455
+ resolve(input: {
6456
+ base: string;
6457
+ instance?: string | SystemPromptOverride;
6458
+ thread?: string | SystemPromptOverride;
6459
+ call?: string | SystemPromptOverride;
6460
+ }, traceId?: string): Promise<string>;
6461
+ /**
6462
+ * Renders a template string by replacing variable placeholders with provided values.
6463
+ *
6464
+ * @remarks
6465
+ * Supported placeholder format: {{variableName}}
6466
+ * - Variable names are trimmed of whitespace
6467
+ * - Missing variables render as empty strings
6468
+ * - Values are converted to strings using String()
6469
+ *
6470
+ * This simple templating system supports basic variable interpolation.
6471
+ * It does not support complex features like loops, conditionals, or nested objects.
6472
+ *
6473
+ * @param template - The template string containing variable placeholders.
6474
+ * @param variables - Record of variable names to their string or string-convertible values.
6475
+ *
6476
+ * @returns The rendered string with all placeholders substituted.
6477
+ *
6478
+ * @private
6479
+ * @example
6480
+ * ```typescript
6481
+ * const rendered = renderTemplate(
6482
+ * 'Hello {{name}}, you are {{age}} years old.',
6483
+ * { name: 'Alice', age: 30 }
6484
+ * );
6485
+ * // Result: 'Hello Alice, you are 30 years old.'
6486
+ * ```
6487
+ */
6488
+ private renderTemplate;
6489
+ }
6490
+
5354
6491
  /**
5355
6492
  * Generates a unique Version 4 UUID (Universally Unique Identifier) string.
5356
6493
  *
@@ -5418,6 +6555,6 @@ declare const generateUUID: () => string;
5418
6555
  /**
5419
6556
  * The current version of the ART Framework package.
5420
6557
  */
5421
- declare const VERSION = "0.4.7";
6558
+ declare const VERSION = "0.4.11";
5422
6559
 
5423
- export { type A2AAgentInfo, type A2ATask, type A2ATaskEvent, type A2ATaskFilter, type A2ATaskMetadata, A2ATaskPriority, type A2ATaskResult, A2ATaskSocket, A2ATaskStatus, ARTError, AdapterInstantiationError, type AgentDiscoveryConfig, AgentDiscoveryService, AgentFactory, type AgentFinalResponse, type AgentOptions, type AgentPersona, type AgentProps, type AgentState, AnthropicAdapter, type AnthropicAdapterOptions, ApiKeyStrategy, ApiQueueTimeoutError, type ArtInstance, type ArtInstanceConfig, type ArtStandardMessage, type ArtStandardMessageRole, ArtStandardMessageSchema, type ArtStandardPrompt, ArtStandardPromptSchema, AuthManager, type AvailableProviderEntry, CalculatorTool, type CallOptions, type ConversationManager, type ConversationMessage, ConversationSocket, type CreateA2ATaskRequest, DeepSeekAdapter, type DeepSeekAdapterOptions, ErrorCode, type ExecutionContext, type ExecutionMetadata, type ExecutionOutput, type FilterOptions, type FormattedPrompt, GeminiAdapter, type GeminiAdapterOptions, GenericOAuthStrategy, GroqAdapter, type GroqAdapterOptions, type IA2ATaskRepository, type IAgentCore, type IAuthStrategy, type IConversationRepository, type IObservationRepository, type IProviderManager, type IStateRepository, type IToolExecutor, type ITypedSocket, InMemoryStorageAdapter, IndexedDBStorageAdapter, type JsonObjectSchema, type JsonSchema, type LLMMetadata, LLMStreamSocket, LocalInstanceBusyError, LocalProviderConflictError, LogLevel, Logger, type LoggerConfig, type ManagedAdapterAccessor, McpClientController, McpManager, type McpManagerConfig, McpProxyTool, type McpResource, type McpResourceTemplate, type McpServerConfig, type McpServerStatus, type McpToolDefinition, type MessageOptions, MessageRole, ModelCapability, type OAuthConfig, type Observation, type ObservationFilter, type ObservationManager, ObservationSocket, ObservationType, OllamaAdapter, type OllamaAdapterOptions, OpenAIAdapter, type OpenAIAdapterOptions, OpenRouterAdapter, type OpenRouterAdapterOptions, type OutputParser, PESAgent, type PESAgentStateData, type PKCEOAuthConfig, PKCEOAuthStrategy, type ParsedToolCall, type PromptBlueprint, type PromptContext, type ProviderAdapter, type ProviderManagerConfig, ProviderManagerImpl, type ReasoningEngine, type RuntimeProviderConfig, type StageSpecificPrompts, StateManager, type StateSavingStrategy, type StorageAdapter, type StreamEvent, type StreamEventTypeFilter, SupabaseStorageAdapter, type SystemPromptMergeStrategy, type SystemPromptOverride, type SystemPromptResolver, type SystemPromptSpec, type SystemPromptsRegistry, type TaskDelegationConfig, TaskDelegationService, type TaskStatusResponse, type ThreadConfig, type ThreadContext, type TodoItem, TodoItemStatus, ToolRegistry, type ToolResult, type ToolSchema, type ToolSystem, TypedSocket, UISystem, UnknownProviderError, type UnsubscribeFunction, type UpdateA2ATaskRequest, VERSION, type ZyntopiaOAuthConfig, ZyntopiaOAuthStrategy, createArtInstance, generateUUID };
6560
+ export { type A2AAgentInfo, type A2ATask, type A2ATaskEvent, type A2ATaskFilter, type A2ATaskMetadata, A2ATaskPriority, type A2ATaskResult, A2ATaskSocket, A2ATaskStatus, ARTError, AdapterInstantiationError, type AgentDiscoveryConfig, AgentDiscoveryService, AgentFactory, type AgentFinalResponse, type AgentOptions, type AgentPersona, type AgentProps, type AgentState, AnthropicAdapter, type AnthropicAdapterOptions, ApiKeyStrategy, ApiQueueTimeoutError, type ArtInstance, type ArtInstanceConfig, type ArtStandardMessage, type ArtStandardMessageRole, ArtStandardMessageSchema, type ArtStandardPrompt, ArtStandardPromptSchema, AuthManager, type AvailableProviderEntry, CalculatorTool, type CallOptions, type ConversationManager, type ConversationMessage, ConversationSocket, type CreateA2ATaskRequest, DeepSeekAdapter, type DeepSeekAdapterOptions, ErrorCode, type ExecutionConfig, type ExecutionContext, type ExecutionMetadata, type ExecutionOutput, type FilterOptions, type FormattedPrompt, GeminiAdapter, type GeminiAdapterOptions, GenericOAuthStrategy, GroqAdapter, type GroqAdapterOptions, type IA2ATaskRepository, type IAgentCore, type IAuthStrategy, type IConversationRepository, type IObservationRepository, type IProviderManager, type IStateRepository, type IToolExecutor, type ITypedSocket, InMemoryStorageAdapter, IndexedDBStorageAdapter, type JsonObjectSchema, type JsonSchema, type LLMMetadata, LLMStreamSocket, LocalInstanceBusyError, LocalProviderConflictError, LogLevel, Logger, type LoggerConfig, type ManagedAdapterAccessor, McpClientController, McpManager, type McpManagerConfig, McpProxyTool, type McpResource, type McpResourceTemplate, type McpServerConfig, type McpServerStatus, type McpToolDefinition, type MessageOptions, MessageRole, ModelCapability, type OAuthConfig, type Observation, type ObservationFilter, type ObservationManager, ObservationSocket, ObservationType, OllamaAdapter, type OllamaAdapterOptions, OpenAIAdapter, type OpenAIAdapterOptions, OpenRouterAdapter, type OpenRouterAdapterOptions, OutputParser, PESAgent, type PESAgentStateData, type PKCEOAuthConfig, PKCEOAuthStrategy, type ParsedToolCall, type PromptBlueprint, type PromptContext, type ProviderAdapter, type ProviderManagerConfig, ProviderManagerImpl, ReasoningEngine, type RuntimeProviderConfig, type StageSpecificPrompts, StateManager, type StateSavingStrategy, type StepOutputEntry, type StorageAdapter, type StreamEvent, type StreamEventTypeFilter, SupabaseStorageAdapter, type SystemPromptMergeStrategy, type SystemPromptOverride, SystemPromptResolver, type SystemPromptSpec, type SystemPromptsRegistry, type TaskDelegationConfig, TaskDelegationService, type TaskStatusResponse, type ThreadConfig, type ThreadContext, type TodoItem, TodoItemStatus, ToolRegistry, type ToolResult, type ToolSchema, type ToolSystem, TypedSocket, UISystem, UnknownProviderError, type UnsubscribeFunction, type UpdateA2ATaskRequest, VERSION, type ZyntopiaOAuthConfig, ZyntopiaOAuthStrategy, createArtInstance, generateUUID };