Skip to content

Iamsdt/agentflow-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

48 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AgentFlow Client

npm version TypeScript React License: MIT

A TypeScript/React client library for the AgentFlow multi-agent system API. Build conversational AI applications with streaming responses, tool execution, and dynamic state management.

✨ Features

  • πŸš€ Simple API - Clean, intuitive client for AgentFlow
  • πŸ’¬ Streaming Support - Real-time streaming responses for chat UIs
  • πŸ”§ Tool Execution - Automatic local tool execution with recursion handling
  • πŸ“Š State Management - Dynamic state schema with validation
  • βš›οΈ React Ready - Built for React applications with hooks and patterns
  • πŸ“˜ TypeScript First - Full TypeScript support with comprehensive types
  • 🎯 Zero Config - Works out of the box with sensible defaults

πŸ“¦ Installation

npm install @10xscale/agentflow-client
# or
yarn add @10xscale/agentflow-client
# or
pnpm add @10xscale/agentflow-client

πŸš€ Quick Start

Basic Usage

import { AgentFlowClient, Message } from '@10xscale/agentflow-client';

// Initialize client
const client = new AgentFlowClient({
  baseUrl: 'http://localhost:8000',
  authToken: 'your-token', // optional
  debug: true              // optional
});

// Send a message and get response
const result = await client.invoke([
  Message.text_message('Hello, how can you help me?', 'user')
]);

console.log(result.messages); // Array of response messages

Streaming Chat

// Stream responses in real-time
const stream = client.stream([
  Message.text_message('Tell me a story', 'user')
]);

for await (const chunk of stream) {
  if (chunk.event === 'message') {
    console.log(chunk.message?.content);
  }
}

React Integration

import { useState } from 'react';
import { AgentFlowClient, Message } from '@10xscale/agentflow-client';

function ChatComponent() {
  const [messages, setMessages] = useState<Message[]>([]);
  const client = new AgentFlowClient({ baseUrl: 'http://localhost:8000' });

  const sendMessage = async (text: string) => {
    const userMsg = Message.text_message(text, 'user');
    setMessages(prev => [...prev, userMsg]);

    const result = await client.invoke([...messages, userMsg]);
    setMessages(result.messages);
  };

  return (
    <div>
      {messages.map((msg, i) => (
        <div key={i}>{msg.content}</div>
      ))}
    </div>
  );
}

Tool Registration

⚠️ Important: Remote tools (registered client-side) should only be used for browser-level APIs like localStorage, navigator.geolocation, etc. For most operations (database queries, external API calls, calculations), define your tools in the Python backend instead. See Tools Guide for details.

// Register custom tools for agent execution (ONLY for browser APIs)
client.registerTool({
  node: 'assistant',
  name: 'get_weather',
  description: 'Get current weather for a location',
  parameters: {
    type: 'object',
    properties: {
      location: { type: 'string' }
    },
    required: ['location']
  },
  handler: async ({ location }) => {
    // Your tool logic here
    return { temperature: 72, conditions: 'sunny' };
  }
});

// Tools execute automatically during invoke
const result = await client.invoke([
  Message.text_message('What is the weather in NYC?', 'user')
]);

πŸ“š Documentation

Getting Started

Core Concepts

  • Invoke API - Request/response pattern with tool execution
  • Stream API - Real-time streaming responses
  • State Schema - Dynamic state management and validation
  • Tools Guide - Tool registration and execution ⚠️ Important: Remote vs Backend tools

React Integration

Reference

🎯 Key APIs

invoke() - Batch Processing

Execute agent with automatic tool execution loop:

const result = await client.invoke(messages, {
  recursion_limit: 25,
  response_granularity: 'full'
});

stream() - Real-time Streaming

Stream responses as they're generated:

const stream = client.stream(messages);
for await (const chunk of stream) {
  // Process chunks in real-time
}

graphStateSchema() - Dynamic Schema

Get agent state schema for form generation and validation:

const schema = await client.graphStateSchema();
// Build forms, validate data, generate types

Tool Registration

Register local tools that agents can execute:

client.registerTool({
  node: 'node_name',
  name: 'tool_name',
  handler: async (args) => { /* ... */ }
});

πŸ’‘ Examples

Check out the examples/ directory for complete working examples:

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Your React App    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β”‚ AgentFlowClient
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  @10xscale/agentflow-client    β”‚  ← This library
β”‚  - Client           β”‚
β”‚  - Tools            β”‚
β”‚  - Messages         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β”‚ HTTP/HTTPS
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  AgentFlow Server   β”‚  ← Your backend
β”‚  (Multi-agent API)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Configuration

const client = new AgentFlowClient({
  baseUrl: string,           // Required: API base URL
  authToken?: string,        // Optional: Bearer token
  timeout?: number,          // Optional: Request timeout (default: 5min)
  debug?: boolean            // Optional: Enable debug logging
});

πŸ§ͺ Testing

# Run all tests
npm test

# Run tests once
npm run test:run

# Build the library
npm run build

πŸ“ TypeScript Support

Full TypeScript support with comprehensive type definitions:

import type {
  AgentFlowClient,
  Message,
  ToolRegistration,
  InvokeResult,
  StreamChunk,
  AgentState,
  AgentStateSchema
} from '@10xscale/agentflow-client';

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

πŸ™ Acknowledgments

Built for the AgentFlow multi-agent system framework.


Made with ❀️ for the AgentFlow community

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published