update a2a
This commit is contained in:
parent
cd02d65efe
commit
91dc7bbc99
|
|
@ -3,6 +3,8 @@ import asyncio
|
||||||
import asyncclick as click # Using asyncclick for async main
|
import asyncclick as click # Using asyncclick for async main
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import json # For potentially inspecting raw errors
|
import json # For potentially inspecting raw errors
|
||||||
|
import anyio
|
||||||
|
import functools
|
||||||
|
|
||||||
# Import from the common directory placed alongside this script
|
# Import from the common directory placed alongside this script
|
||||||
from common.client import A2AClient
|
from common.client import A2AClient
|
||||||
|
|
@ -51,17 +53,20 @@ async def cli(agent_url: str):
|
||||||
while True:
|
while True:
|
||||||
taskId = uuid4().hex # Generate a new task ID for each interaction
|
taskId = uuid4().hex # Generate a new task ID for each interaction
|
||||||
try:
|
try:
|
||||||
prompt = await click.prompt(
|
# Use functools.partial to prepare the prompt function call
|
||||||
|
prompt_func = functools.partial(
|
||||||
|
click.prompt,
|
||||||
colorize(C_CYAN, "\nEnter your question (:q or quit to exit)"),
|
colorize(C_CYAN, "\nEnter your question (:q or quit to exit)"),
|
||||||
prompt_suffix=" > ",
|
prompt_suffix=" > ",
|
||||||
type=str # Ensure prompt returns string
|
type=str
|
||||||
)
|
)
|
||||||
except RuntimeError:
|
# Run the synchronous prompt function in a worker thread
|
||||||
# This can happen if stdin is closed, e.g., in some test runners
|
prompt = await anyio.to_thread.run_sync(prompt_func)
|
||||||
print(colorize(C_RED, "Failed to read input. Exiting."))
|
except (EOFError, RuntimeError, KeyboardInterrupt):
|
||||||
|
# Catch potential errors during input or if stdin closes
|
||||||
|
print(colorize(C_RED, "\nInput closed or interrupted. Exiting."))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
if prompt.lower() in [":q", "quit"]:
|
if prompt.lower() in [":q", "quit"]:
|
||||||
print(colorize(C_YELLOW, "Exiting client."))
|
print(colorize(C_YELLOW, "Exiting client."))
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from common.server import A2AServer
|
||||||
from common.types import AgentCard, AgentCapabilities, AgentSkill, MissingAPIKeyError
|
from common.types import AgentCard, AgentCapabilities, AgentSkill, MissingAPIKeyError
|
||||||
|
|
||||||
# Import your custom TaskManager (which now imports from your original files)
|
# Import your custom TaskManager (which now imports from your original files)
|
||||||
from .task_manager import PocketFlowTaskManager
|
from task_manager import PocketFlowTaskManager
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,6 @@ click>=8.0.0,<9.0.0
|
||||||
|
|
||||||
# For A2A Client
|
# For A2A Client
|
||||||
httpx>=0.27.0,<0.28.0
|
httpx>=0.27.0,<0.28.0
|
||||||
|
httpx-sse>=0.4.0
|
||||||
asyncclick>=8.1.8 # Or just 'click' if you prefer asyncio.run
|
asyncclick>=8.1.8 # Or just 'click' if you prefer asyncio.run
|
||||||
pydantic>=2.0.0,<3.0.0 # For common.types
|
pydantic>=2.0.0,<3.0.0 # For common.types
|
||||||
|
|
@ -9,13 +9,13 @@ from common.types import (
|
||||||
JSONRPCResponse, SendTaskRequest, SendTaskResponse,
|
JSONRPCResponse, SendTaskRequest, SendTaskResponse,
|
||||||
SendTaskStreamingRequest, SendTaskStreamingResponse, Task, TaskSendParams,
|
SendTaskStreamingRequest, SendTaskStreamingResponse, Task, TaskSendParams,
|
||||||
TaskState, TaskStatus, TextPart, Artifact, UnsupportedOperationError,
|
TaskState, TaskStatus, TextPart, Artifact, UnsupportedOperationError,
|
||||||
InternalError, InvalidParamsError
|
InternalError, InvalidParamsError,
|
||||||
|
Message
|
||||||
)
|
)
|
||||||
import common.server.utils as server_utils
|
import common.server.utils as server_utils
|
||||||
|
|
||||||
# Import directly from your original PocketFlow files
|
# Import directly from your original PocketFlow files
|
||||||
from .flow import create_agent_flow # Assumes flow.py is in the same directory
|
from flow import create_agent_flow
|
||||||
from .utils import call_llm, search_web # Make utils functions available if needed elsewhere
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -62,9 +62,10 @@ class PocketFlowTaskManager(InMemoryTaskManager):
|
||||||
# executor to avoid blocking the event loop. For simplicity here, we run it directly.
|
# executor to avoid blocking the event loop. For simplicity here, we run it directly.
|
||||||
# Consider adding a timeout if flows can hang.
|
# Consider adding a timeout if flows can hang.
|
||||||
logger.info(f"Running PocketFlow for task {task_params.id}...")
|
logger.info(f"Running PocketFlow for task {task_params.id}...")
|
||||||
final_state_dict = agent_flow.run(shared_data)
|
agent_flow.run(shared_data) # Run the flow, modifying shared_data in place
|
||||||
logger.info(f"PocketFlow completed for task {task_params.id}")
|
logger.info(f"PocketFlow completed for task {task_params.id}")
|
||||||
answer_text = final_state_dict.get("answer", "Agent did not produce a final answer text.")
|
# Access the original shared_data dictionary, which was modified by the flow
|
||||||
|
answer_text = shared_data.get("answer", "Agent did not produce a final answer text.")
|
||||||
|
|
||||||
# --- Package result into A2A Task ---
|
# --- Package result into A2A Task ---
|
||||||
final_task_status = TaskStatus(state=TaskState.COMPLETED)
|
final_task_status = TaskStatus(state=TaskState.COMPLETED)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue