use-build-prompt-options.ts


Overview

The use-build-prompt-options.ts file provides a custom React hook, useBuildPromptExtraPromptOptions, designed to generate a set of enriched prompt options for use in an agent-based flow or UI. These prompt options are dynamically constructed by fetching predefined prompt templates, wrapping them with specific tags, and conditionally filtering them based on the presence of sub-agents or tools connected to a given node. This utility enhances the flexibility and contextual relevance of prompts used within a prompt-driven agent framework, specifically within a React application.


Detailed Breakdown

Constants

PromptIdentity: string


Functions

wrapPromptWithTag(text: string, tag: string): string


Hook

useBuildPromptExtraPromptOptions(edges: Edge[], nodeId?: string): { extraOptions: Array }


Important Implementation Details


Interaction With Other Parts of the System


Visual Diagram

flowchart TD
    A[useBuildPromptExtraPromptOptions] --> B[useFetchPrompt]
    A --> C[useTranslation (i18n)]
    A --> D[hasSubAgentOrTool]
    A --> E[wrapPromptWithTag]

    subgraph "Output"
        F[extraOptions: Array]
    end

    B -->|prompts data| A
    C -->|t() function| A
    D -->|has boolean| A
    E -->|wrap text with tag| A
    A --> F

Summary

The use-build-prompt-options.ts file encapsulates a specialized React hook that builds a categorized list of prompt options by fetching prompt templates, wrapping them with tags, and filtering based on graph connectivity. It serves as a key piece in a prompt-driven agent system, enabling dynamic and context-aware prompt customization that integrates tightly with the agent graph and localization infrastructure. This hook is intended for UI components that require flexible and enriched prompt options in complex agent workflows.