Skip to Content

HasuFlow

Star on GitHub

Create Your First Harness

This tutorial shows you how to use the HasuFlow Harness programmatically — importing and using HasuFlow directly in your Python code rather than through the web interface.

Prerequisites

  • Python 3.12+
  • uv installed
  • HasuFlow repository cloned

Install

cd hasu-flow/backend uv sync

Create configuration

Create a minimal config.yaml:

config_version: 6 models: - name: gpt-4o use: langchain_openai:ChatOpenAI model: gpt-4o api_key: $OPENAI_API_KEY sandbox: use: hasuflow.sandbox.local:LocalSandboxProvider tools: - use: hasuflow.community.ddg_search.tools:web_search_tool - use: hasuflow.sandbox.tools:read_file_tool - use: hasuflow.sandbox.tools:write_file_tool

Write the code

Create a Python file

Create my_agent.py in the backend/ directory:

import asyncio import os from hasuflow.client import HasuFlowClient from hasuflow.config import load_config os.environ["OPENAI_API_KEY"] = "sk-..." # Load config.yaml load_config() client = HasuFlowClient() 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

cd backend uv run python my_agent.py

What the events look like

The stream yields events like:

{"type": "messages", "data": {"content": "def fibonacci..."}} {"type": "thread_state", "data": {"title": "Python Fibonacci Function"}}

Next steps