-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman_streamlit.py
70 lines (55 loc) · 2.07 KB
/
human_streamlit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from langgraph.graph import END, StateGraph
from typing import TypedDict
from pydantic import BaseModel
from content_creator import content_creator
from digital_artist import digital_artist
# Define la estructura del estado
class StateSchema(TypedDict):
input_to_agent: str
agent_choice: str
agent_use_tool_respond: str
# Clase de estado para el flujo
class State(BaseModel):
input_to_agent: str
agent_choice: str = None
agent_use_tool_respond: str = None
# Asignación del agente
def human_assign_to_agent(state):
"""
Asigna un agente seleccionado previamente en el estado.
"""
if not state.agent_choice:
return {"agent_choice": "content_creator"}
return {"agent_choice": state.agent_choice}
# Ejecución del agente seleccionado
def agent_execute_task(state):
"""
Ejecuta la tarea según el agente seleccionado.
"""
input_to_agent = state.input_to_agent
choosen_agent = state.agent_choice
# Ejecuta el agente correspondiente
if choosen_agent == "content_creator":
structured_respond = content_creator.invoke({"product_desc": input_to_agent})
respond = '\n'.join([
f"**Title:** {structured_respond.Title}",
f"**Message:** {structured_respond.Message}",
f"**Tags:** {' '.join(structured_respond.Tags)}"
])
elif choosen_agent == "digital_artist":
respond = digital_artist.invoke(input_to_agent)
else:
respond = "Por favor, seleccione un agente válido: 'ContentCreator' o 'DigitalArtist'."
return {"input_to_agent": input_to_agent, "agent_choice": choosen_agent, "agent_use_tool_respond": respond}
# Define el flujo de trabajo
workflow = StateGraph(State)
# Nodo inicial
workflow.add_node("start", human_assign_to_agent)
# Nodo final
workflow.add_node("end", agent_execute_task)
# Configuración del flujo
workflow.set_entry_point("start")
workflow.add_edge("start", "end")
workflow.add_edge("end", END)
# Compilación del flujo en un Runnable
app = workflow.compile()