b62ac7672a
Agent-Logs-Url: https://github.com/bytedance/deer-flow/sessions/a5f192e7-8034-4e46-af22-60b90ee27d40 Co-authored-by: foreleven <4785594+foreleven@users.noreply.github.com>
100 lines
1.8 KiB
Plaintext
100 lines
1.8 KiB
Plaintext
import { Callout, Steps } from "nextra/components";
|
|
|
|
# Create Your First Harness
|
|
|
|
This tutorial shows you how to use the DeerFlow Harness programmatically — importing and using DeerFlow directly in your Python code rather than through the web interface.
|
|
|
|
## Prerequisites
|
|
|
|
- Python 3.12+
|
|
- `uv` installed
|
|
- DeerFlow repository cloned
|
|
|
|
## Install
|
|
|
|
```bash
|
|
cd deer-flow/backend
|
|
uv sync
|
|
```
|
|
|
|
## Create configuration
|
|
|
|
Create a minimal `config.yaml`:
|
|
|
|
```yaml
|
|
config_version: 6
|
|
|
|
models:
|
|
- name: gpt-4o
|
|
use: langchain_openai:ChatOpenAI
|
|
model: gpt-4o
|
|
api_key: $OPENAI_API_KEY
|
|
|
|
sandbox:
|
|
use: deerflow.sandbox.local:LocalSandboxProvider
|
|
|
|
tools:
|
|
- use: deerflow.community.ddg_search.tools:web_search_tool
|
|
- use: deerflow.sandbox.tools:read_file_tool
|
|
- use: deerflow.sandbox.tools:write_file_tool
|
|
```
|
|
|
|
## Write the code
|
|
|
|
<Steps>
|
|
|
|
### Create a Python file
|
|
|
|
Create `my_agent.py` in the `backend/` directory:
|
|
|
|
```python
|
|
import asyncio
|
|
import os
|
|
from deerflow.client import DeerFlowClient
|
|
from deerflow.config import load_config
|
|
|
|
os.environ["OPENAI_API_KEY"] = "sk-..."
|
|
|
|
# Load config.yaml
|
|
load_config()
|
|
|
|
client = DeerFlowClient()
|
|
|
|
async def main():
|
|
async for event in client.astream(
|
|
thread_id="my-first-thread",
|
|
message="Write a Python fibonacci function with a docstring",
|
|
config={
|
|
"configurable": {
|
|
"model_name": "gpt-4o",
|
|
}
|
|
},
|
|
):
|
|
print(event)
|
|
|
|
asyncio.run(main())
|
|
```
|
|
|
|
### Run it
|
|
|
|
```bash
|
|
cd backend
|
|
uv run python my_agent.py
|
|
```
|
|
|
|
</Steps>
|
|
|
|
## What the events look like
|
|
|
|
The stream yields events like:
|
|
|
|
```python
|
|
{"type": "messages", "data": {"content": "def fibonacci..."}}
|
|
{"type": "thread_state", "data": {"title": "Python Fibonacci Function"}}
|
|
```
|
|
|
|
## Next steps
|
|
|
|
- [Use Tools and Skills](/docs/tutorials/use-tools-and-skills)
|
|
- [Harness Quick Start](/docs/harness/quick-start)
|