Skip to content

Add Agent API examples and comprehensive README - #13904

Closed
princeaeri06-droid wants to merge 2 commits into
infiniflow:mainfrom
princeaeri06-droid:feature/agent-api-examples
Closed

princeaeri06-droid wants to merge 2 commits into
infiniflow:mainfrom
princeaeri06-droid:feature/agent-api-examples

Conversation

@princeaeri06-droid

@princeaeri06-droid princeaeri06-droid commented Apr 2, 2026 •

Copy link
Copy Markdown
  • Add agent_example.py: Python SDK example for agent CRUD and sessions
  • Add agent_example.sh: cURL examples for Agent HTTP API
  • Add README.md: Comprehensive guide for all API examples
  • Covers agent lifecycle, session management, streaming/non-streaming
  • Includes troubleshooting, quick start, and API reference

Fixes #4310

What problem does this PR solve?

Briefly describe what this PR aims to solve. Include background context that will help reviewers understand the purpose of the PR.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update

- Add agent_example.py: Python SDK example for agent CRUD and sessions
- Add agent_example.sh: cURL examples for Agent HTTP API
- Add README.md: Comprehensive guide for all API examples
- Covers agent lifecycle, session management, streaming/non-streaming
- Includes troubleshooting, quick start, and API reference

Fixes infiniflow#4310

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings April 2, 2026 12:10
@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Apr 2, 2026
@princeaeri06-droid

Copy link
Copy Markdown
Author

done some changes

@princeaeri06-droid

Copy link
Copy Markdown
Author

some new changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new “agent” API examples under example/ to address #4310 by providing runnable SDK and cURL snippets, plus a consolidated README intended to guide developers through common workflows.

Changes:

  • Added a Python SDK example for agent CRUD + basic session management.
  • Added a cURL script covering agent CRUD, session lifecycle, and agent completion calls.
  • Added an example/README.md intended as a comprehensive index/quickstart for API examples.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
example/sdk/agent_example.py New Python example demonstrating agent lifecycle + session CRUD.
example/http/agent_example.sh New cURL example covering agent CRUD, sessions, and completions.
example/README.md New “comprehensive” README describing example layout, quickstart, and patterns.

Comment on lines +29 to +31

HOST_ADDRESS = "http://127.0.0.1"
API_KEY = "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm"

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example hard-codes an API key that looks like a real credential. Please replace with a placeholder (e.g., ragflow-{your_api_key}) or read from an environment variable so secrets aren’t committed to the repo.

Suggested change
HOST_ADDRESS = "http://127.0.0.1"
API_KEY = "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm"
import os
HOST_ADDRESS = "http://127.0.0.1"
API_KEY = os.getenv("RAGFLOW_API_KEY", "ragflow-{your_api_key}")

Copilot uses AI. Check for mistakes.
from ragflow_sdk import RAGFlow
import sys

HOST_ADDRESS = "http://127.0.0.1"

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOST_ADDRESS is set to http://127.0.0.1 (no port), but the default Docker deployment (and the cURL examples below) use http://localhost:9380. Consider updating the example to use http://127.0.0.1:9380 (or document why port 80 is expected) to prevent copy/paste failures.

Suggested change
HOST_ADDRESS = "http://127.0.0.1"
HOST_ADDRESS = "http://127.0.0.1:9380" # Default RAGFlow Docker port

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +92
# List agents to get the created agent
print("Listing agents...")
agents = ragflow_instance.list_agents(page=1, page_size=10, orderby="create_time", desc=True)
if not agents:
raise Exception("No agents found after creation")

agent_instance = agents[0] # Get the most recently created agent
print(f"Agent created: {agent_instance.id} - {agent_instance.description}")

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example finds the created agent by listing agents and taking agents[0], which can select (and later delete) the wrong agent in a non-empty tenant. Prefer using a unique title (e.g., include a timestamp) and filtering via list_agents(title=...), or capture the created agent ID from the create response if available.

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +25

# Create an agent
echo -e "\n-- Create an agent"
curl --request POST \
--url http://localhost:9380/api/v1/agents \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm' \

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script hard-codes a Bearer token that appears to be an actual API key. Replace it with a placeholder or reference an environment variable (e.g., $API_KEY) to avoid committing credentials and to make the script reusable.

Suggested change
# Create an agent
echo -e "\n-- Create an agent"
curl --request POST \
--url http://localhost:9380/api/v1/agents \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm' \
# Set API_KEY in your environment before running, e.g.:
# export API_KEY="your-api-key-here"
# Create an agent
echo -e "\n-- Create an agent"
curl --request POST \
--url http://localhost:9380/api/v1/agents \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${API_KEY}" \

Copilot uses AI. Check for mistakes.
Comment thread example/README.md
Comment on lines +9 to +23
├── sdk/ # Python SDK examples
│ ├── dataset_example.py # Dataset CRUD operations
│ ├── chat_example.py # Chat management and completions
│ ├── document_example.py # Document upload and processing
│ ├── retrieval_example.py # Knowledge base retrieval
│ └── agent_example.py # Agent CRUD and session management
│
├── http/ # cURL/HTTP examples
│ ├── dataset_example.sh
│ ├── chat_example.sh
│ ├── document_example.sh
│ ├── retrieval_example.sh
│ └── agent_example.sh
│
└── chat_demo/ # Chat demo application

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README’s directory structure and guide reference several example files that don’t exist in example/sdk/ or example/http/ (e.g., chat_example.py, document_example.py, retrieval_example.py and corresponding .sh). Either add these files as part of the PR or update the README to only describe the examples that are actually present.

Suggested change
├── sdk/ # Python SDK examples
│ ├── dataset_example.py # Dataset CRUD operations
│ ├── chat_example.py # Chat management and completions
│ ├── document_example.py # Document upload and processing
│ ├── retrieval_example.py # Knowledge base retrieval
│ └── agent_example.py # Agent CRUD and session management
│
├── http/ # cURL/HTTP examples
│ ├── dataset_example.sh
│ ├── chat_example.sh
│ ├── document_example.sh
│ ├── retrieval_example.sh
│ └── agent_example.sh
│
└── chat_demo/ # Chat demo application
├── sdk/ # Python SDK examples (datasets, agents, etc.)
├── http/ # cURL/HTTP examples corresponding to the SDK examples
└── chat_demo/ # Chat demo application

Copilot uses AI. Check for mistakes.
Comment thread example/README.md
Comment on lines +159 to +171
### 5. Agent Examples ⭐ **NEW**

**What it demonstrates:**
- Create and manage AI agents with custom workflows
- Agent session management
- Execute agents (streaming/non-streaming)
- Agent DSL (Domain Specific Language) structure
- Basic agent components (Begin, LLM)

**Python SDK:**
```bash
python example/sdk/agent_example.py
```

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README claims the Python SDK agent example demonstrates executing agents (streaming/non-streaming), but example/sdk/agent_example.py currently only does agent/session CRUD and never calls Session.ask(...) to run a completion. Please either add an execution example to the Python script or adjust this section to match the actual behavior.

Copilot uses AI. Check for mistakes.
Comment thread example/README.md
Comment on lines +30 to +56
1. **Running RAGFlow Instance**
```bash
# Start RAGFlow with Docker
docker compose up -d
```

2. **API Key**
- Log in to RAGFlow admin panel (default: http://localhost:9380)
- Go to Settings → API Keys
- Generate a new API key (format: `ragflow-{token}`)

3. **Python SDK** (for SDK examples)
```bash
pip install ragflow-sdk
```

### Configuration

Replace these values in the examples:

| Variable | Location | How to Find |
|----------|----------|-------------|
| `API_KEY` | All examples | RAGFlow admin panel → Settings → API Keys |
| `HOST_ADDRESS` | All examples | Your RAGFlow server URL (default: `http://127.0.0.1`) |
| `AGENT_ID` | Agent examples | Response from create agent or list agents |
| `SESSION_ID` | Agent examples | Response from create session |
| `DATASET_ID` | Dataset examples | Response from create dataset or list datasets |

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README has conflicting defaults for the server address: it suggests the admin panel/API default is on localhost:9380, but the configuration table lists HOST_ADDRESS default as http://127.0.0.1 (no port), and the SDK examples use that value. Please make these defaults consistent (and clarify that the SDK base_url should not include /api/v1 since the SDK appends it).

Copilot uses AI. Check for mistakes.
JinHai-CN pushed a commit that referenced this pull request May 22, 2026
… and retrieval (#4310) (#14208)

Closes #4310

### What problem does this PR solve?

Issue #4310 requests practical examples for the RAGFlow SDK and HTTP API
to help developers get started faster. The existing `example/sdk/`
folder only contains `dataset_example.py`. This PR fills the remaining
gaps by adding examples for three key API areas not yet covered in
`main` or by other open PRs (#13904, #13284):

- **Chunk management** — add, list, update, delete, and retrieve chunks
within a dataset
- **Chat assistant** — create a chat assistant, open a session, send
messages (streaming and non-streaming), and clean up
- **Retrieval** — perform semantic retrieval across one or multiple
datasets

### Type of change

- [x] Documentation Update
- [x] New Feature (non-breaking change which adds functionality)
@yuzhichang yuzhichang closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Examples on RAGFlow API

3 participants