feat: add ai agent http agent
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
- 观察信息包含玩家筹码、公共牌、当前玩家手牌、底池、历史动作、可用动作和跟注/加注边界。
|
||||
- 支持盲注、四条街下注、弃牌、过牌、跟注、下注、加注、全下、边池和摊牌结算。
|
||||
- 支持本地 Agent 和 HTTP Agent。
|
||||
- 支持 Human Agent 和 OpenAI-compatible AI Agent 的终端过程输出。
|
||||
|
||||
## 运行服务
|
||||
|
||||
@@ -60,7 +61,7 @@ curl http://127.0.0.1:8000/games/demo
|
||||
"name": "LLM Agent",
|
||||
"agent": {
|
||||
"type": "http",
|
||||
"endpoint": "http://127.0.0.1:9001/act",
|
||||
"endpoint": "http://127.0.0.1:9101",
|
||||
"timeout_seconds": 10
|
||||
}
|
||||
}
|
||||
@@ -83,8 +84,31 @@ curl http://127.0.0.1:8000/games/demo
|
||||
|
||||
`bet` 和 `raise` 的 `amount` 表示当前下注轮中该玩家希望达到的总下注额,也就是观察中 `amount_mode: "street_total"` 的含义。
|
||||
|
||||
## AI Agent
|
||||
|
||||
启动一个可接入 OpenAI-compatible Chat Completions API 的 AI Agent:
|
||||
|
||||
```bash
|
||||
python -m texas_holdem.ai_client \
|
||||
--host 127.0.0.1 \
|
||||
--port 9101 \
|
||||
--base-url https://api.openai.com/v1 \
|
||||
--api-key "$OPENAI_API_KEY" \
|
||||
--model gpt-4o-mini \
|
||||
--keep-history
|
||||
```
|
||||
|
||||
AI Agent 会在终端输出:
|
||||
|
||||
- 收到的 `/game` 游戏快照;
|
||||
- 收到的 `/act` 行动请求;
|
||||
- 大模型流式返回内容,默认灰色显示;
|
||||
- 最终解析出的 action,或失败时的 fallback action。
|
||||
|
||||
默认每次 `/act` 会清屏,和 Human Agent 一致;加 `--keep-history` 后保留历史滚动输出。可用 `--no-stream` 关闭流式请求,用 `--no-color` 关闭灰色 ANSI 输出。
|
||||
|
||||
## 测试
|
||||
|
||||
```bash
|
||||
python -m unittest discover -s tests -v
|
||||
python -m unittest discover -v
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user