File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515import asyncio
1616import os
1717from dataclasses import dataclass
18- from datetime import datetime
1918from pathlib import Path
2019from typing import Any
2120
@@ -181,15 +180,10 @@ async def main() -> None:
181180 )
182181
183182 # Verifica si hay checkpoints existentes para reanudar
184- checkpoints = await storage .list_checkpoints (workflow_name = workflow .name )
185- if checkpoints :
186- sorted_cps = sorted (checkpoints , key = lambda cp : datetime .fromisoformat (cp .timestamp ))
187- latest = sorted_cps [- 1 ]
188- print (
189- f"📂 Se encontraron { len (sorted_cps )} checkpoint(s)."
190- f" Reanudando desde el más reciente: { latest .checkpoint_id } "
191- )
192- stream = workflow .run (checkpoint_id = latest .checkpoint_id , stream = True )
183+ checkpoint = await storage .get_latest (workflow_name = workflow .name )
184+ if checkpoint :
185+ print (f"📂 Se encontró un checkpoint. Reanudando desde el más reciente: { checkpoint .checkpoint_id } " )
186+ stream = workflow .run (checkpoint_id = checkpoint .checkpoint_id , stream = True )
193187 else :
194188 brief = (
195189 "Presenta nuestra nueva freidora de aire compacta con canasta de 5 cuartos. Menciona el precio de $89, "
Original file line number Diff line number Diff line change @@ -274,11 +274,10 @@ async def main() -> None:
274274 )
275275
276276 # Verifica si hay checkpoints existentes para reanudar
277- checkpoints = await storage .list_checkpoints (workflow_name = workflow .name )
278- if checkpoints :
279- latest = checkpoints [- 1 ] # ya ordenados por timestamp
280- print (f"📂 Se encontraron { len (checkpoints )} checkpoint(s) en PostgreSQL. Reanudando desde el más reciente." )
281- stream = workflow .run (checkpoint_id = latest .checkpoint_id , stream = True )
277+ checkpoint = await storage .get_latest (workflow_name = workflow .name )
278+ if checkpoint :
279+ print (f"📂 Se encontró un checkpoint en PostgreSQL. Reanudando desde el más reciente." )
280+ stream = workflow .run (checkpoint_id = checkpoint .checkpoint_id , stream = True )
282281 else :
283282 brief = (
284283 "Presenta nuestra nueva freidora de aire compacta con canasta de 5 cuartos. Menciona el precio de $89, "
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ def process_return(
5656 return_type : Annotated [str , "Either 'refund' or 'replacement'" ],
5757) -> str :
5858 """Procesa una devolución de producto para el pedido indicado."""
59+ print (f"\n 🔧 [Herramienta llamada: process_return(order_number={ order_number } , return_type={ return_type } )]" )
5960 return f"Devolución procesada para el pedido { order_number } : { return_type } aprobado. Correo de confirmación enviado."
6061
6162
@@ -70,6 +71,7 @@ def process_return(
7071 "return_agent para devoluciones. No puedes manejar problemas específicos tú mismo — siempre transfiere. "
7172 "Si un especialista acaba de terminar de ayudar, pregunta al cliente si necesita algo más "
7273 "— NO reenvíes al mismo especialista. "
74+ "Los números de pedido son solo de 3 dígitos."
7375 "NO pidas información de contacto, correo electrónico ni número de teléfono. "
7476 "NO digas 'Adiós' hasta que el cliente confirme explícitamente que no tiene más preguntas."
7577 ),
@@ -80,6 +82,7 @@ def process_return(
8082 name = "order_agent" ,
8183 instructions = (
8284 "Eres el especialista en seguimiento de pedidos. Ayuda al cliente a verificar el estado de su pedido. "
85+ "Si el cliente necesita devolver un pedido, transfiere a return_agent. "
8386 "Cuando termines, transfiere de vuelta a triage_agent."
8487 ),
8588)
Original file line number Diff line number Diff line change 1515import asyncio
1616import os
1717from dataclasses import dataclass
18- from datetime import datetime
1918from pathlib import Path
2019from typing import Any
2120
@@ -181,12 +180,10 @@ async def main() -> None:
181180 )
182181
183182 # Check if there are existing checkpoints to resume from
184- checkpoints = await storage .list_checkpoints (workflow_name = workflow .name )
185- if checkpoints :
186- sorted_cps = sorted (checkpoints , key = lambda cp : datetime .fromisoformat (cp .timestamp ))
187- latest = sorted_cps [- 1 ]
188- print (f"📂 Found { len (sorted_cps )} checkpoint(s). Resuming from latest: { latest .checkpoint_id } " )
189- stream = workflow .run (checkpoint_id = latest .checkpoint_id , stream = True )
183+ checkpoint = await storage .get_latest (workflow_name = workflow .name )
184+ if checkpoint :
185+ print (f"📂 Found checkpoint. Resuming from latest: { checkpoint .checkpoint_id } " )
186+ stream = workflow .run (checkpoint_id = checkpoint .checkpoint_id , stream = True )
190187 else :
191188 brief = (
192189 "Introduce our new compact air fryer with a 5-quart basket. Mention the $89 price, "
Original file line number Diff line number Diff line change @@ -274,11 +274,10 @@ async def main() -> None:
274274 )
275275
276276 # Check if there are existing checkpoints to resume from
277- checkpoints = await storage .list_checkpoints (workflow_name = workflow .name )
278- if checkpoints :
279- latest = checkpoints [- 1 ] # already sorted by timestamp
280- print (f"📂 Found { len (checkpoints )} checkpoint(s) in PostgreSQL. Resuming from latest." )
281- stream = workflow .run (checkpoint_id = latest .checkpoint_id , stream = True )
277+ checkpoint = await storage .get_latest (workflow_name = workflow .name )
278+ if checkpoint :
279+ print (f"📂 Found a checkpoint in PostgreSQL. Resuming from latest." )
280+ stream = workflow .run (checkpoint_id = checkpoint .checkpoint_id , stream = True )
282281 else :
283282 brief = (
284283 "Introduce our new compact air fryer with a 5-quart basket. Mention the $89 price, "
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ def process_return(
5656 return_type : Annotated [str , "Either 'refund' or 'replacement'" ],
5757) -> str :
5858 """Process a product return for the given order."""
59+ print (f"\n 🔧 [Tool called: process_return(order_number={ order_number } , return_type={ return_type } )]" )
5960 return f"Return processed for order { order_number } : { return_type } approved. Confirmation email sent."
6061
6162
@@ -70,6 +71,7 @@ def process_return(
7071 "return_agent for returns. You cannot handle specific issues yourself — always hand off. "
7172 "If a specialist has just finished helping, ask the customer if there is anything else "
7273 "they need help with — do NOT re-route to the same specialist. "
74+ "Order numbers are only 3 digits long."
7375 "Do NOT ask for contact information, email, or phone number. "
7476 "Do NOT say 'Goodbye' until the customer explicitly confirms they have no more questions."
7577 ),
@@ -79,7 +81,8 @@ def process_return(
7981 client = client ,
8082 name = "order_agent" ,
8183 instructions = (
82- "You are the order tracking specialist. Help the customer check order status. "
84+ "You are the order tracking specialist. Help the customer check status of pending orders. "
85+ "If the customer needs to return an order, hand off to return_agent. "
8386 "When done, hand off back to triage_agent."
8487 ),
8588)
You can’t perform that action at this time.
0 commit comments