fix: PEP8 Style
This commit is contained in:
@@ -6,24 +6,22 @@ from langchain_core.runnables import RunnableConfig
|
||||
from typing import Literal, Callable, Any, Union
|
||||
from .schemas import MessagesState
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class AgentConfig:
|
||||
"""Configuración inmutable del agente para fácil testing."""
|
||||
system_prompt: str = (
|
||||
"helpful assistant that can call tools when needed. Always respond with a message. "
|
||||
"helpful assistant that can call tools when needed."
|
||||
" Always respond with a message."
|
||||
)
|
||||
max_iterations: int = 10
|
||||
max_iterations: int = 200
|
||||
timeout_seconds: float = 30.0
|
||||
|
||||
|
||||
class Agent:
|
||||
"""
|
||||
Agente conversacional basado en LangGraph.
|
||||
|
||||
Soporta tools pasadas como lista de instancias.
|
||||
"""
|
||||
|
||||
@@ -36,7 +34,7 @@ class Agent:
|
||||
):
|
||||
"""
|
||||
Inicializa el agente.
|
||||
|
||||
|
||||
Args:
|
||||
model: Modelo LLM a usar
|
||||
config: Configuración del agente (AgentConfig)
|
||||
@@ -49,7 +47,7 @@ class Agent:
|
||||
self._config = config or AgentConfig()
|
||||
self._tools = tools or []
|
||||
self._checkpointer = checkpointer or InMemorySaver()
|
||||
|
||||
|
||||
self._tools_by_name: dict[str, Any] = {
|
||||
tool.name: tool for tool in self._tools
|
||||
}
|
||||
@@ -73,7 +71,9 @@ class Agent:
|
||||
"""Expone el grafo para inspección en tests."""
|
||||
return self._build_agent()
|
||||
|
||||
async def ainvoke(self, state: dict, config: RunnableConfig | None = None) -> dict:
|
||||
async def ainvoke(
|
||||
self, state: dict, config: RunnableConfig | None = None
|
||||
) -> dict:
|
||||
"""
|
||||
Versión asíncrona de invoke, necesaria para checkpointers de DB.
|
||||
"""
|
||||
@@ -86,7 +86,9 @@ class Agent:
|
||||
# Llamamos al método ainvoke del grafo compilado
|
||||
return await self._compiled_agent.ainvoke(state, config=config)
|
||||
|
||||
def invoke(self, state: dict, config: RunnableConfig | None = None) -> dict:
|
||||
def invoke(
|
||||
self, state: dict, config: RunnableConfig | None = None
|
||||
) -> dict:
|
||||
"""
|
||||
Ejecuta el agente con el estado inicial.
|
||||
|
||||
@@ -98,7 +100,7 @@ class Agent:
|
||||
"""
|
||||
|
||||
if not config:
|
||||
config : RunnableConfig = {"configurable": {"thread_id": "1"}}
|
||||
config: RunnableConfig = {"configurable": {"thread_id": "1"}}
|
||||
|
||||
if "messages" not in state:
|
||||
raise ValueError("State must contain 'messages' key")
|
||||
|
||||
Reference in New Issue
Block a user