Spaces:
Sleeping
Sleeping
File size: 1,439 Bytes
f49023b cc6bd3b d5ce935 910ae58 cc6bd3b d5ce935 cc6bd3b f49023b cc6bd3b f49023b fae0e51 cc6bd3b f49023b cc6bd3b 910ae58 cc6bd3b 910ae58 cc6bd3b e4f6727 f49023b fae0e51 cc6bd3b f49023b cc6bd3b |
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 |
from typing import Any, Dict
from args import Args
from graph import State
from graph_builder import GraphBuilder
class Alfred:
def __init__(self):
print("Agent initialized.")
self.graph_builder = GraphBuilder()
self.agent_graph = self.graph_builder.build_agent_graph()
def __call__(self, question: str) -> str:
print(f"Agent received question (first 50 chars): {question[:50]}...")
result = self.process_query(question)
response = result["final_response"]
print(f"Agent processed the response: {response}")
return response
def process_query(self, query: str) -> Dict[str, Any]:
"""
Process a query through the agent graph.
Args:
query: The initial query to process
Returns:
The final state of the graph execution
"""
initial_state: State = {
"initial_query": query,
"messages": [query], # Manager's context
"task_progress": [], # Solver's context
"audit_interval": Args.AlfredParams.AUDIT_INTERVAL,
"manager_queries": 0,
"solver_queries": 0,
"max_interactions": Args.AlfredParams.MAX_INTERACTIONS,
"max_solving_effort": Args.AlfredParams.MAX_SOLVING_EFFORT,
"final_response": None
}
result = self.agent_graph.invoke(initial_state)
return result
|