-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path01_basic_agent.py
More file actions
68 lines (56 loc) · 1.98 KB
/
Copy path01_basic_agent.py
File metadata and controls
68 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# /// script
# requires-python = ">=3.11"
# dependencies = ["band-sdk[opencode]"]
#
# [tool.uv.sources]
# band-sdk = { git = "https://github.com/band-ai/band-sdk-python.git" }
# ///
"""
Basic OpenCode adapter agent example.
Prerequisites (see `examples/opencode/README.md` for the full setup):
1. Install OpenCode: `npm install -g opencode-ai`
2. Give the server a provider key: the default provider is OpenCode Zen, whose
models are hosted and need a Zen API key
3. Start the server from an empty throwaway directory, so a small model answers
instead of exploring a checkout:
`cd "$(mktemp -d)" && opencode serve --hostname=127.0.0.1 --port=4096`
4. Set `BAND_WS_URL` and `BAND_REST_URL`
5. Add agent credentials to `agent_config.yaml`
Run with:
uv run examples/opencode/01_basic_agent.py
"""
from __future__ import annotations
import asyncio
import logging
from settings import OpenCodeExampleSettings
from band import Agent, configure_logging
from band.adapters.opencode import OpencodeAdapter, OpencodeAdapterConfig
from band.core.types import Emit
configure_logging(
level=logging.INFO,
stream="stdout",
root_level=logging.INFO,
extra_loggers={"httpx": logging.WARNING},
)
logger = logging.getLogger(__name__)
async def main() -> None:
settings = OpenCodeExampleSettings()
adapter = OpencodeAdapter(
config=OpencodeAdapterConfig(
base_url=settings.opencode_base_url,
provider_id=settings.opencode_provider_id,
model_id=settings.opencode_model_id,
agent=settings.opencode_agent,
custom_section="You are a helpful assistant. Keep replies concise.",
approval_mode=settings.opencode_approval_mode,
),
emit=Emit.TOOL_CALLS,
)
logger.info("Starting OpenCode agent: %s", settings.agent_key)
async with Agent.from_config(
settings.agent_key,
adapter=adapter,
) as agent:
await agent.run_forever()
if __name__ == "__main__":
asyncio.run(main())