Skip to content

Commit dc3b1f5

Browse files
Copilothiyouga
andcommitted
Add integration README and fix linting
Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com>
1 parent 6265dc4 commit dc3b1f5

2 files changed

Lines changed: 104 additions & 1 deletion

File tree

src_py/integration/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Integration Module
2+
3+
This module contains integration tools for AgentHub, including conversation tracing and a web UI for interacting with LLMs.
4+
5+
## Components
6+
7+
### Tracer
8+
9+
The `Tracer` class provides functionality to save conversation history to local files and browse them via a web interface.
10+
11+
**Features:**
12+
- Save conversation history as JSON and text files
13+
- Web interface for browsing saved conversations
14+
- Automatic serialization of complex data types
15+
16+
**Usage:**
17+
18+
```python
19+
from integration import Tracer
20+
21+
# Initialize tracer
22+
tracer = Tracer(cache_dir="cache")
23+
24+
# Save conversation history
25+
history = [
26+
{"role": "user", "content_items": [{"type": "text", "text": "Hello"}]},
27+
{"role": "assistant", "content_items": [{"type": "text", "text": "Hi there!"}]}
28+
]
29+
config = {"temperature": 0.7}
30+
tracer.save_history(history, "conversation_001", config)
31+
32+
# Start web server to browse saved conversations
33+
tracer.start_web_server(host="127.0.0.1", port=5000)
34+
```
35+
36+
**With AutoLLMClient:**
37+
38+
```python
39+
from agenthub import AutoLLMClient
40+
41+
client = AutoLLMClient(model="gemini-3-flash-preview")
42+
config = {"trace_id": "agent1/conversation_001", "temperature": 0.7}
43+
44+
message = {"role": "user", "content_items": [{"type": "text", "text": "Hello"}]}
45+
async for _ in client.streaming_response_stateful(message=message, config=config):
46+
pass
47+
# Conversation is automatically saved to cache/agent1/conversation_001.json and .txt
48+
```
49+
50+
### Web UI
51+
52+
The Web UI provides an interactive chat interface for communicating with LLMs through a web browser.
53+
54+
**Features:**
55+
- Interactive chat interface
56+
- Editable configuration (model, temperature, max_tokens)
57+
- Streaming message display
58+
- Message cards showing token usage and finish reason
59+
- Support for multiple AI models (Gemini, Claude, GLM)
60+
61+
**Usage:**
62+
63+
```python
64+
from integration import start_chat_server
65+
66+
# Start the chat server
67+
start_chat_server(host="127.0.0.1", port=5001, debug=False)
68+
# Open http://127.0.0.1:5001 in your browser
69+
```
70+
71+
**Or run the example:**
72+
73+
```bash
74+
python examples/web_ui_example.py
75+
```
76+
77+
**Features:**
78+
- **Config Panel**: Click the "⚙️ Config" button to edit:
79+
- Model selection (Gemini 3 Flash, Claude Sonnet 4.5, GLM 4.7)
80+
- Temperature (0-2)
81+
- Max Tokens
82+
- **Message Input**: Type messages in the input box (Shift+Enter for new line, Enter to send)
83+
- **Message Cards**: Each message is displayed as a card with:
84+
- Role indicator (User/Assistant)
85+
- Message content
86+
- Token usage (in bottom-right corner)
87+
- Finish reason (in bottom-right corner)
88+
- **Streaming**: Responses stream in real-time as the model generates them
89+
- **Clear**: Clear the conversation history
90+
91+
## Examples
92+
93+
See the `examples/` directory for usage examples:
94+
- `trace_example.py` - Demonstrates conversation tracing
95+
- `web_ui_example.py` - Starts the web UI server
96+
97+
## API Endpoints
98+
99+
The Web UI exposes the following endpoints:
100+
101+
- `GET /` - Main chat interface
102+
- `POST /api/chat` - Chat API endpoint (accepts streaming requests)
103+
- Request body: `{"message": {...}, "config": {...}, "history": [...]}`
104+
- Response: Server-Sent Events (SSE) stream with chat events

src_py/tests/test_web_ui.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import pytest
1615
from flask import Flask
1716

1817
from integration.web_ui import create_chat_app

0 commit comments

Comments
 (0)