agent.ts


Overview

The agent.ts file defines TypeScript interfaces and type aliases that model the data structures for a complex flow-based system, likely related to AI agent workflows, DSL (Domain Specific Language) components, and conversational or task automation flows. This file primarily contains type definitions for various nodes, forms, and graph representations used in the system, focusing on configuration, flow control, agent logs, and interaction with components.

These types enable strongly-typed development of components interacting with AI agents, switch conditions, categorization items, retrieval processes, code execution, and agent prompts, among others. They serve as a foundational contract for the system's data flow, facilitating flow construction, execution, and logging.


Detailed Descriptions

Interfaces and Types


1. ICategorizeItem

Represents an item that can be categorized within the system.

Usage Example:

const categoryItem: ICategorizeItem = {
  name: "Urgent",
  index: 1,
  to: ["node_2"],
  uuid: "abc-123"
};

2. ICategorizeItemResult

A mapped record keyed by string, representing categorize items but omitting name, examples, and uuid fields from ICategorizeItem. The examples property here is simplified to an array of strings.

This type is used to represent processed categorize results keyed by some identifier.


3. ISwitchCondition, ISwitchItem, and ISwitchForm

These interfaces model conditional branching logic within flows.


4. DSL, DSLComponents, IOperator, and IOperatorNode

These interfaces describe the Domain Specific Language (DSL) structure used to define flows and operators in the system.


5. IFlow and IFlowTemplate

Represent a flow and its template in the system.


6. Various Form Interfaces

These interfaces define the forms for different operators in the flow.


7. Node Data and Node Types


8. Graph and Trace Interfaces


9. Agent Logs Interfaces


Important Implementation Details


Interaction with Other System Parts


Usage Examples

Defining a Switch Condition

const condition: ISwitchCondition = {
  items: [
    { cpn_id: "comp1", operator: "==", value: "yes" },
    { cpn_id: "comp2", operator: ">", value: "10" }
  ],
  logical_operator: "AND",
  to: ["next_node"]
};

Constructing a Generate Node

const generateNode: IGenerateNode = {
  id: "node1",
  data: {
    label: "Generate",
    name: "Text Generation",
    form: {
      max_tokens: 100,
      temperature: 0.7,
      prompt: 1,
      llm_id: "gpt-4",
      parameters: { key: "input", component_id: "comp1" }
    }
  },
  position: { x: 0, y: 0 }
};

Building a Flow Graph

const graph: IGraph = {
  nodes: [generateNode /*, other nodes */],
  edges: [{ id: "e1", source: "node1", target: "node2" }]
};

Mermaid Diagram: Class Diagram of Key Interfaces

classDiagram
    class ICategorizeItem {
        +string name
        +string description?
        +Array~{value: string} examples?
        +number index
        +string[] to
        +string uuid
    }

    class ISwitchItem {
        +string cpn_id
        +string operator
        +string value
    }

    class ISwitchCondition {
        +ISwitchItem[] items
        +string logical_operator
        +string[] to
    }

    class ISwitchForm {
        +ISwitchCondition[] conditions
        +string[] end_cpn_ids
        +string no
    }

    class IOperatorNode {
        +string component_name
        +Record~string, unknown~ params
    }

    class IOperator {
        +IOperatorNode obj
        +string[] downstream
        +string[] upstream
        +string parent_id?
    }

    class DSL {
        +DSLComponents components
        +any[] history
        +string[] path?
        +any[] answer?
        +IGraph graph?
        +Message[] messages?
        +IReference[] reference?
        +Record~string, any~ globals
        +IReference[] retrieval
    }

    class IAgentForm {
        +string sys_prompt
        +Array~{role: string, content: string} prompts
        +number max_retries
        +number delay_after_error
        +string visual_files_var
        +number max_rounds
        +Nullable~'comment' | 'go'~ exception_method
        +any exception_comment
        +any exception_goto
        +Array~{name: string, component_name: string, params: Record~string, any~} tools
        +Array~{mcp_id: string, tools: Record~string, Record~string, any~~} mcp
        +{structured_output: Record~string, Record~string, any~~, content: Record~string, any~} outputs
    }

    ICategorizeItemResult <|-- ICategorizeItem
    ISwitchForm --> ISwitchCondition
    ISwitchCondition --> ISwitchItem
    IOperator --> IOperatorNode
    DSL --> IOperator
    IAgentForm --> DSL

Summary

The agent.ts file is a foundational TypeScript module that defines the data models for an AI agent flow system. It includes interfaces for categorization, conditional branching, DSL components, flow templates, various operator forms, graph structures, and agent logs. These definitions facilitate consistent flow construction, execution, and monitoring in an interactive AI workflow platform, likely integrated with React UI components and conversational AI services.

This file does not include executable logic but provides the critical types that power the system's flow definition, validation, and runtime configuration.


End of Documentation