# {{name}} - Interactive Streaming Chat

{{description}}

## Overview

This project provides an interactive streaming chat interface for the Lab agentic process/flow `{{name}}`. Responses stream in real-time as the flow executes through multiple agents and tasks.

## Prerequisites

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

2. **Lab flow/process must exist:**
   The agentic process `{{name}}` should already be created.
   
   If not, create it first using the lab-process-basic template (when available) or manually through the Lab interface.

## Usage

Run the interactive chat:

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

**Features:**
- ✨ Real-time streaming responses
- 💬 Conversation history maintained
- 🔄 Multi-step workflow execution visible
- 🎯 Progress updates via streaming
- ⌨️ 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 Flow: {{name}}
============================================================
Type your questions (or 'quit' to exit)
============================================================

You: Process this request...

{{name}}: [Agent 1] Analyzing request...
[Agent 2] Processing data...
[Task Complete] Here's the result...

You: quit

Goodbye! 👋
```

## About Lab Flows

Lab agentic processes (flows) orchestrate multiple agents and tasks to complete complex workflows. They provide:

- **Multi-agent collaboration** - Different agents handling different steps
- **State management** - Maintaining context across workflow steps
- **Event-driven execution** - Responding to signals and triggers
- **Task coordination** - Sequencing activities and managing dependencies

## 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": 2000
}

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

### Add Context

Prepend a system message to provide workflow context:

```python
messages = [{
    "role": "system",
    "content": "You are executing a multi-step workflow. Follow the process carefully."
}]
```

### Disable Streaming

To get complete responses instead of streaming:

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

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

## Troubleshooting

**Flow not found:**
```
❌ Error: Unable to communicate with specified flow {{name}}
```
→ Verify the flow exists: `geai lab flows list` (or check Lab UI)

**Workflow errors:**
Check flow definition and ensure all required agents/tasks are properly configured.

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

## Next Steps

- Monitor workflow execution and state transitions
- Add persistence for long-running processes
- Implement conversation context management
- Export workflow execution logs

## Documentation

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