Files
openfang/sdk/python/examples/client_basic.py
iven 92e5def702
Some checks failed
CI / Check / macos-latest (push) Has been cancelled
CI / Check / ubuntu-latest (push) Has been cancelled
CI / Check / windows-latest (push) Has been cancelled
CI / Test / macos-latest (push) Has been cancelled
CI / Test / ubuntu-latest (push) Has been cancelled
CI / Test / windows-latest (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Security Audit (push) Has been cancelled
CI / Secrets Scan (push) Has been cancelled
CI / Install Script Smoke Test (push) Has been cancelled
初始化提交
2026-03-01 16:24:24 +08:00

36 lines
818 B
Python

#!/usr/bin/env python3
"""
Basic example — create an agent and chat with it via the REST API.
Usage:
python client_basic.py
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from openfang_client import OpenFang
client = OpenFang("http://localhost:3000")
# Check server health
health = client.health()
print("Server:", health)
# List existing agents
agents = client.agents.list()
print(f"Agents: {len(agents)}")
# Create a new agent from the "assistant" template
agent = client.agents.create(template="assistant")
print(f"Created agent: {agent['id']}")
# Send a message and get the full response
reply = client.agents.message(agent["id"], "What can you help me with?")
print(f"Reply: {reply}")
# Clean up
client.agents.delete(agent["id"])
print("Agent deleted.")