GraphAI Documentation
repository·main·Indexed 18 days ago
https://github.com/receptron/graphaiAn asynchronous data flow execution engine for creating agentic applications using declarative graphs defined in YAML or JSON. GraphAI manages concurrency, dependency flow, and task automation for asynchronous operations such as LLM calls, database queries, and REST APIs. It includes a variety of specialized agents across categories like llm, data, service, and embedding, as well as agent filters for caching, HTTP offloading, streaming, and debugging.
What's inside GraphAI
- GraphAI is an asynchronous data flow execution engine designed for building agentic applications. It allows developers to define agent workflows as declarative data flow graphs using YAML or JSON formats. Instead of writing imperative logic, you describe how data flows between different agents to achieve a complex task.
Use the LLM Agent for unified model interaction
mainThe LLM Agent provides a unified interface to interact with various large language models, including OpenAI, Anthropic, and local models like Ollama (via OpenAI-compatible APIs).
It supports:
- System prompts, user prompts, and messages (conversation history).
- Unified Input/Output Format: Regardless of the backend, inputs and outputs follow a consistent data structure for messages, tool calls, and parameters (e.g.,
temperature,max_tokens). - Cross-Platform execution: Works in both Node.js and Web (browser) environments.
- Streaming: Supported in combination with Agent Filters.
Explore GraphAI implementation samples
mainThis repository contains sample graph data for developers to understand how to compose different agents and nodes to solve complex tasks.
Note: For end-user samples, visit graphai_samples.
Key sample categories include:
- LLM Workflows: Interview simulations, research agents, and graph description tools.
- Interactive Applications: Chat loops, receptionists (information gathering), and weather apps.
- RAG (Retrieval-Augmented Generation): In-memory Wikipedia querying using embeddings and similarity checks.
- Data Processing: RSS feed readers with translation and concurrent processing.
- Meta-Programming: Generating and executing new GraphAI graphs using LLMs.
Explore GraphAI official projects and agents
mainGraphAI provides a ecosystem of official packages to extend its functionality. You can find specialized agents and utility libraries via their respective npm organizations:
- GraphAI Agents: Access a collection of pre-built agents (e.g., LLM, HTTP, or data agents) via the @graphai/graphai organization.
- GraphAI Utilities: Access helper libraries and utilities via the @graphai/receptron organization.
For visual exploration and workflow creation, check out:
- GraphAI web demo: A web-based demonstration of GraphAI capabilities.
- Grapys: A GUI tool designed for creating GraphAI workflows visually.
Explore GraphAI Agents by category
mainGraphAI provides a wide variety of specialized agents categorized by their primary function. You can use these agents to handle different stages of a graph workflow, such as providing initial input, processing data, interacting with LLMs, or performing string and array manipulations.
Available agent categories include:
- input: Agents that provide initial data to the graph (e.g.,
textInputAgent). - data: Agents for data transformation and aggregation (e.g.,
mergeObjectAgent,totalAgent,propertyFilterAgent). - llm: Agents that interface with Large Language Models (e.g.,
anthropicAgent,geminiAgent,openAIAgent,replicateAgent). - service: Agents that interact with external services or APIs (e.g.,
fetchAgent,wikipediaAgent). - sleeper: Agents that manage timing or delays (e.g.,
sleeperAgent). - embedding: Agents for generating vector embeddings (e.g.,
stringEmbeddingsAgent). - string: Agents for text manipulation (e.g.,
stringTemplateAgent,jsonParserAgent). - array: Agents for array operations (e.g.,
pushAgent,arrayFlatAgent). - matrix: Agents for mathematical matrix operations (e.g.,
dotProductAgent). - graph: Agents for managing graph structure (e.g.,
mapAgent,nestedAgent). - image: Agents for image processing (e.g.,
images2messageAgent). - fs: Agents for file system operations (e.g.,
fileReadAgent).
- input: Agents that provide initial data to the graph (e.g.,
What is GraphAI Lite and how does it work?
mainGraphAI Lite is a lightweight version of GraphAI, a declarative data-flow programming framework. It is designed to manage complex applications involving multiple asynchronous calls and concurrent executions.
Instead of manually managing
Promise.allto optimize concurrency, you use a data-flow style where you specify the dependencies for each task (node). The system then automatically determines the optimal execution order, ensuring that independent tasks run concurrently while dependent tasks wait only for their specific requirements.import { computed } from '@receptron/graphai_lite'; const ExecuteAtoF = async () => { const nodeA = FuncA(); const nodeB = FuncB(); const nodeC = FuncC(); const nodeD = computed([nodeA, nodeB], FuncD); const nodeE = computed([nodeB, nodeC], FuncE); const nodeF = computed([nodeD, nodeE], FuncF); return nodeF; };What is an Agent and an Agent Function?
mainAn Agent is an abstract object that takes inputs and generates an output asynchronously (e.g., an LLM call, a database query, or a REST API).
A node associated with an agent is called a Computed Node. The logic that performs the computation is implemented in an Agent Function.
An Agent Function is a TypeScript function that receives a
contextobject of typeAgentFunctionContext. The context includes:params: Agent-specific parameters from the node'sparamsproperty.inputs: The data received from other nodes via theinputsproperty.debugInfo: Information for debugging.
Optional parameters for nested agents/filters:
graphData: An optionalGraphDataobject.agents:AgentFunctionInfoDictionary.taskManager:TaskManager.log:TransactionLog[].filterParams: Parameters for agent filters.
What is GraphAI and Declarative Dataflow Programming?
mainGraphAI is an asynchronous dataflow execution engine used to build agentic applications. Instead of writing traditional imperative code to manage complex asynchronous API calls (like LLMs, databases, or web searches), you describe the dependencies between these calls using a declarative dataflow graph in YAML or JSON.
Key Benefits:
- Concurrency: GraphAI automatically identifies nodes that have no dependencies and executes them concurrently.
- Dependency Management: The engine manages the flow of data between asynchronous tasks.
- Automation: It handles task priority, map-reduce processing, error handling, retries, and logging automatically.
Implement loops in a dataflow graph
mainSince dataflow graphs must be acyclic, GraphAI provides a
loopproperty at the graph level to control iterative execution. A loop can be controlled by two optional properties:count: Specifies the exact number of times the graph executes.while: Specifies a data source to check after each iteration. The loop continues as long as the value from that data source is truthy (non-null, non-undefined, non-zero, non-false, non-NaN, and non-empty array/string).
To implement a loop, you typically use the
updateproperty on static nodes to refresh their values based on the results of the previous iteration, eventually reaching a state that breaks thewhilecondition.version: 0.5 loop: while: :people nodes: people: value: - Steve Jobs - Elon Musk - Nikola Tesla update: :retriever.array result: value: [] update: :reducer.array isResult: true retriever: agent: shiftAgent inputs: array: :people query: agent: openAIAgent params: system: Describe about the person in less than 100 words model: gpt-4o inputs: prompt: :retriever.item reducer: agent: pushAgent inputs: array: :result item: :query.textHow streamAgentFilterGenerator works for streaming data
mainThe
streamAgentFilterGeneratorallows you to receive stream data externally via astreamTokenCallbackprovided in the filter parameters. This is useful for handling real-time token streaming in both server and client environments.Server-side implementation (Express)
In an Express server, you can use the callback to write tokens directly to the response stream (e.g., for Server-Sent Events):
const callback = (context: AgentFunctionContext, token: string) => { if (token) { res.write(token); } }; const streamAgentFilter = { name: "streamAgentFilter", agent: streamAgentFilterGenerator<string>(callback), };Client-side implementation (Web)
In a web client, you can use a callback to update local state (like a Vue
ref) as tokens arrive:const callback = (context: AgentFunctionContext, data: string) => { const { nodeId } = context.debugInfo; streamingData.value[nodeId] = (streamingData.value[nodeId] ?? "") + data; }; const agentFilters = [ { name: "streamAgentFilter", agent: streamAgentFilterGenerator(callback), agentIds: streamAgents, }, ];// Example of the callback pattern used by streamAgentFilterGenerator const callback = (context: AgentFunctionContext, token: string) => { if (token) { // Handle the token (e.g., res.write(token) or updating UI state) } };Structure GraphData for OpenAI Agents
mainGraphData is a JSON-based format used to define a computational graph where nodes represent agents and edges represent data flow. To use OpenAI agents, define nodes in the
nodesobject. Each node can specify anagent(e.g.,openAIAgentoropenAIImageAgent),inputs(using the:nodeNamesyntax to reference values from other nodes), andparamsfor agent-specific configuration.Key properties for nodes:
agent: The identifier of the agent to use.inputs: An object mapping agent input keys to values or references to other nodes (e.g.,"prompt": ":inputData").params: Configuration parameters such asmodel,system,max_tokens, orimages.isResult: A boolean indicating if this node's output is the final result of the graph.
{ "version": 0.5, "nodes": { "inputData": { "value": "hello, let me know the answer 1 + 1" }, "llm": { "agent": "openAIAgent", "inputs": { "prompt": ":inputData" }, "params": { "max_tokens": 2000 } } } }How Agents and Agent Functions work
mainAn Agent is an abstract object that takes inputs and generates an asynchronous output (e.g., an LLM call, a database query, or a REST API call).
An Agent Function is the TypeScript implementation of an agent. It receives a
contextobject of typeAgentFunctionContextcontaining:params: Agent-specific parameters from the node'sparamsproperty.inputs: Data received from other nodes via theinputsproperty.debugInfo: Information for debugging.
Optional parameters for nested agents/filters:
graphData: For nested agents.agents: For nested agents.taskManager: For nested agents.log: For nested agents.filterParams: For agent filters.