# {{name}} - Interactive Streaming Chat

{{description}}

## Overview

This project provides an interactive streaming chat interface for the Lab agent `{{name}}`. Responses stream in real-time for a better user experience, and tool calls are visible during execution.

## Prerequisites

1. **PyGEAI installed and configured:**
   ```bash
   pip install pygeai
   geai configure --key YOUR_API_KEY --url YOUR_API_URL
   ```

2. **Lab agent must exist:**
   The agent `{{name}}` should already be created.
   
   If not, create it first:
   ```bash
   # Use lab-agent-basic template to create agent
   geai generate create --template lab-agent-basic --output ./my-agent --name {{name}}
   cd my-agent
   python create_{{name}}.py
   ```

## Usage

Run the interactive chat:

```bash
python chat_{{name}}.py
```

**Features:**
- ✨ Real-time streaming responses
- 💬 Conversation history maintained
- 🔧 Tool calls visible (if agent has tools)
- ⌨️ Simple text interface

**Commands:**
- Type your question and press Enter
- Type `quit`, `exit`, or `q` to end the session
- Press `Ctrl+C` to interrupt

## Example Session

```
💬 Interactive Chat with Lab Agent: {{name}}
============================================================
Type your questions (or 'quit' to exit)
============================================================

You: Hello, how can you help me?

{{name}}: I can assist you with various tasks...

You: What's the weather like?

{{name}}: I don't have access to real-time weather data...

You: quit

Goodbye! 👋
```

## Customization

### Modify LLM Settings

Edit `chat_{{name}}.py` to adjust temperature, max tokens, etc:

```python
from pygeai.chat.settings import LLM_SETTINGS

# Override settings
custom_settings = {
    **LLM_SETTINGS,
    "temperature": 0.5,
    "max_tokens": 1000
}

response_stream = client.chat_completion(
    model=f"saia:agent:{agent_name}",
    messages=messages,
    stream=True,
    **custom_settings
)
```

### Add System Prompt

Prepend a system message to guide the agent:

```python
messages = [{
    "role": "system",
    "content": "You are a helpful assistant. Be concise and professional."
}]
```

### Disable Streaming

To get complete responses instead of streaming:

```python
response = client.chat_completion(
    model=f"saia:agent:{agent_name}",
    messages=messages,
    stream=False,
    **LLM_SETTINGS
)

answer = response['choices'][0]['message']['content']
print(f"\n{agent_name}: {answer}\n")
```

### Handle Tool Calls

If your agent uses tools, you can inspect tool calls:

```python
# Note: The streaming response may include tool call information
# Check the response structure for tool_calls in the message
```

## Troubleshooting

**Agent not found:**
```
❌ Error: Unable to communicate with specified agent {{name}}
```
→ Verify the agent exists: `geai lab agents list`

**Connection errors:**
Check your configuration: `geai config show`

**Slow responses:**
Streaming should be faster. Check your network connection.

## Next Steps

- Add conversation persistence (save/load chat history)
- Implement multi-turn context management
- Add web UI (use web-ui-gradio template)
- Export conversation logs

## Documentation

- [PyGEAI Lab Documentation](https://pygeai.readthedocs.io/)
- [Chat Client API](https://pygeai.readthedocs.io/en/latest/chat/)
- [Lab Agents Guide](https://pygeai.readthedocs.io/en/latest/lab/agents/)
