> For the complete documentation index, see [llms.txt](https://saptiva.gitbook.io/saptiva-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://saptiva.gitbook.io/saptiva-docs/saptiva-agents/quick-start.md).

# Quick Start

Con **Saptiva-Agents**, puedes crear rápidamente aplicaciones utilizando agentes preconfigurados. Para ilustrarlo, comenzaremos creando un solo agente capaz de usar herramientas (tools).

```python
from saptiva_agents.ui import Console

from saptiva_agents import SAPTIVA_LEGACY
from saptiva_agents.agents import AssistantAgent
from saptiva_agents.base import SaptivaAIChatCompletionClient


# Define el cliente de modelo de Saptiva.
# El parámetro de cliente api_key debe configurarse ya sea pasando api_key al cliente 
# o configurando la variable de entorno SAPTIVA_API_KEY
model_client = SaptivaAIChatCompletionClient(
    model=SAPTIVA_LEGACY,
    api_key="TU_SAPTIVA_API_KEY",
)

# Define una herramienta simple que el agente puede usar.
# Para este ejemplo, usamos una herramienta ficticia para obtener el clima.
async def get_weather(city: str) -> str:
    """Obtiene el clima para una ciudad específica."""
    return f"El clima en {city} es de 37 grados y soleado."

# Define un AssistantAgent con el modelo, herramienta, mensaje del sistema y reflexión habilitada.
# El mensaje del sistema instruye al agente mediante lenguaje natural.
agent = AssistantAgent(
    name="weather_agent",
    model_client=model_client,
    tools=[get_weather],
    system_message="Eres un asistente útil.",
    reflect_on_tool_use=True,
    model_client_stream=True,  # Habilita la transmisión en tiempo real desde el modelo.
)

# Ejecuta el agente y transmite los mensajes a la consola.
async def main() -> None:
    await Console(agent.run_stream(task="¿Cuál es el clima en Nueva York?"))
    # Cierra la conexión con el cliente modelo.
    await model_client.close()
    
# NOTA: Si ejecutas esto en un script de Python, necesitarás usar asyncio.run(main()).
await main()
```

***

### Ejemplo de Interacción:

```bash
---------- user ----------
¿Cuál es el clima en Nueva York?

---------- weather_agent ----------
[FunctionCall(id='call_bE5CYAwB7OlOdNAyPjwOkej1', arguments='{"city":"Nueva York"}', name='get_weather')]

---------- weather_agent ----------
[FunctionExecutionResult(content='El clima en Nueva York es de 37 grados y soleado.', call_id='call_bE5CYAwB7OlOdNAyPjwOkej1', is_error=False)]

---------- weather_agent ----------
El clima actual en Nueva York es de 37 grados y soleado.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://saptiva.gitbook.io/saptiva-docs/saptiva-agents/quick-start.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
