GenSX Documentation
repository·main·Indexed 19 days ago
https://github.com/gensx-inc/gensxGenSX is a TypeScript-based workflow engine for building complex LLM applications, such as agents and chatbots, using functional composition instead of traditional graph-based models. It includes tools for deploying workflows to GenSX Cloud, managing them via the GenSX console, and running them locally via a CLI or API server. The engine supports integrations with providers like Anthropic, OpenAI, and Perplexity, and features capabilities for persistent chat memory and automated content generation.
What's inside GenSX
- GenSX is a TypeScript framework and workflow engine designed for building complex LLM applications such as agents, chatbots, and long-running workflows. Unlike graph-oriented frameworks that use nodes and edges, GenSX uses a functional composition model where workflows are built by composing pure TypeScript functions called Components.
Overview of GenSX App Templates
mainGenSX provides several Next.js-based templates to jumpstart development:
Chat UX
Focuses on chat-based interfaces. Features include:
- Streaming chat: Real-time message streaming.
- AI thinking: Visible reasoning process.
- Tool integration: Built-in tools for web scraping, search, and data processing.
- Thread history: Persistent history using GenSX Storage.
Deep Research
Focuses on iterative research workflows. Features include:
- Multi-step streaming workflow: Iterative process for building reports.
- Web search and summarization: Uses Tavily for search and extractive summarization.
- Detailed report generation: Creates structured, in-depth reports.
Draft Pad
Focuses on AI-powered writing. Features include:
- Real-time streaming: Live content updates.
- Draft versioning: Track and navigate changes.
- Live progress tracking: Detailed workflow event updates.
- Multi-provider support: Works with OpenAI, Anthropic, Google, etc.
Client Side Tools
Focuses on client-side interactivity. Demonstrates how AI can control client-side components like maps via tool calling.
Explore GenSX Basic Examples
mainGenSX provides several basic examples to demonstrate core patterns and provider integrations:
- Reflection: Demonstrates the self-reflection pattern.
- Anthropic Examples: Shows usage of the
@gensx/anthropiccomponent. - OpenAI Examples: Shows usage of the
@gensx/openaicomponent. - Vercel AI SDK Examples: Shows usage of the
@gensx/vercel-aicomponent.
Explore GenSX Full Examples
mainGenSX provides complex, end-to-end workflow examples:
- Hacker News Analyzer: Analyzes HN posts to generate summaries and trends in Paul Graham's writing style.
- Blog Writer: An end-to-end workflow for topic research and content creation.
- Deep Research: Generates reports by researching and summarizing a list of research papers.
- Computer Use: Demonstrates the OpenAI computer use tool with GenSX.
- Text to SQL: Uses database storage to translate natural language into SQL queries.
- RAG: Demonstrates Retrieval Augmented Generation using vector search storage.
- Chat Memory: Shows how to build a chat application with persistent history using blob storage.
What is CLAUDE.md and how does it help?
mainIn GenSX projects,
CLAUDE.mdacts as a persistent memory layer for Claude (or other LLMs). It provides the model with essential context to ensure accurate and contextual assistance. The file typically contains:- Common project commands (build, test, etc.)
- Code style preferences
- Project structure overview
- Common patterns and examples for GenSX components
- LLM provider configuration examples
- Project-specific notes
Implement RAG with the useSearch hook
mainGenSX provides a
useSearchhook to implement Retrieval Augmented Generation (RAG) workflows. This allows an LLM to query a vector search namespace to find relevant information before generating an answer.A typical RAG workflow in GenSX consists of two components:
- Initialization: A component (e.g.,
InitializeSearch) that creates and populates a vector search namespace with data. - Workflow Execution: A component (e.g.,
RagWorkflow) that processes user questions by searching the vector store and using the retrieved context to generate responses.
Data used in these workflows is stored in a GenSX Cloud search namespace.
- Initialization: A component (e.g.,
Implement self-reflection patterns in GenSX workflows
mainSelf-reflection is a prompting technique where an LLM evaluates its own output and then improves it. In GenSX, this is implemented using a
Reflectioncomponent that creates a programmatic loop between an evaluation component and an improvement component.To implement this pattern, you need:
- An evaluation component (
EvaluateFn): Assesses the current output and provides feedback and a decision on whether to continue. - An improvement component (
ImproveFn): Processes the input using the provided feedback to generate a revised version.
The
Reflectioncomponent iterates until either theEvaluateFnreturnscontinueProcessing: falseor themaxIterationslimit is reached.interface ReflectionProps<TInput> { // The initial input to process input: TInput; // Component to process the input and generate new output ImproveFn: (props: { input: TInput; feedback: string }) => Promise<TInput>; // Component to evaluate if we should continue processing and provide feedback EvaluateFn: (props: { input: TInput }) => Promise<ReflectionOutput>; // Maximum number of iterations allowed maxIterations?: number; } const Reflection = gensx.Component( "Reflection", async <TInput>({ input, ImproveFn, EvaluateFn, maxIterations = 3, }: ReflectionProps<TInput>): Promise<TInput> => { let currentInput = input; let iteration = 0; while (iteration < maxIterations) { const { feedback, continueProcessing } = await EvaluateFn({ input: currentInput, }); if (!continueProcessing) { break; } currentInput = await ImproveFn({ input: currentInput, feedback }); iteration++; } return currentInput; }, );- An evaluation component (
Observability and Tracing in GenSX Cloud
mainGenSX Cloud automatically captures detailed execution traces for all workflows and agents without requiring additional instrumentation.
What is captured:
- LLM Calls: Full prompts, parameters, and responses.
- Tool Invocations: Input arguments and return values.
- Component Lifecycle: Inputs, outputs, and intermediate state changes for every component.
- Execution Flow: A hierarchical component tree and timeline of execution.
Analysis Tools:
- Timeline View: Visualizes the sequence and duration of component execution.
- Component Tree: Navigates the hierarchical structure of the workflow.
- Input/Output Inspector: Examines data flowing between components.
- Error Highlighting: Identifies exactly where failures occurred.
// Traces are automatically captured when workflows are executed // No additional instrumentation required const result = await MyWorkflow({ input: "some query" });Understand SQL database environments
mainGenSX SQL databases provide a seamless transition between local development and cloud production:
- Local development: Databases are stored as SQLite files in the
.gensx/databasesdirectory by default usinglibsql. - Cloud deployment: Databases are automatically provisioned in the cloud (powered by Turso) with millisecond latency.
No code changes are required when moving from development to production environments.
- Local development: Databases are stored as SQLite files in the
How the Human-in-the-Loop mechanism works
mainThe
requestInputmechanism operates through the following lifecycle:- URL Generation: GenSX generates a unique callback URL tied to the specific execution node.
- Triggering: The
callbackUrlis passed into your provided trigger function. - Pausing: The workflow execution is paused at the
await requestInput(...)line. - Resumption: Once a
POSTrequest is received at thecallbackUrl, the workflow resumes with the request body as the return value.
The callback URL follows this format:
${process.env.GENSX_API_BASE_URL}/org/${process.env.GENSX_ORG}/workflowExecutions/${process.env.GENSX_EXECUTION_ID}/fulfill/${nodeId}How GenSX represents workflows as trees
mainGenSX uses a tree-based model for workflow orchestration instead of an explicit graph of nodes and edges. Workflows are expressed using JSX-like syntax where each component represents a step in the process.
Data flows through the tree via child functions (render props pattern). A parent component executes and passes its output to a child function, which then allows the next component in the workflow to be nested. This makes data dependencies explicit and avoids global state.
Key benefits:
- Explicit Dependencies: Each child component only receives what its parent explicitly provides.
- Readability: The workflow reads top-to-bottom like standard code.
- Testability: Components are treated as pure functions of their inputs, making them easy to isolate and test.
<FetchHNPosts limit={postCount}> {(stories) => ( <AnalyzeHNPosts stories={stories}> {({ analyses }) => ( <GenerateReport analyses={analyses}> {(report) => ( <EditReport content={report}> {(editedReport) => ( <WriteTweet context={editedReport} prompt="Summarize the HN trends in a tweet" /> )} </EditReport> )} </GenerateReport> )} </AnalyzeHNPosts> )} </FetchHNPosts>Implement automatic contextual logging
mainGenSX supports contextual logging, which automatically captures relevant metadata (like query parameters, stack traces, or variable states) without requiring manual string formatting. This reduces boilerplate and provides richer debugging information.
Instead of manually including error details in a string, you can pass a simple message, and the logger will enrich the entry with the necessary context.
# Traditional logging approach logger.error(f"Database query failed: {error}") # With automatic contextual logging logger.error("Query failed") # Automatically includes query details, parameters, and stack trace