File size: 1,359 Bytes
910ae58
cc6bd3b
d5ce935
910ae58
 
cc6bd3b
 
 
 
 
d5ce935
cc6bd3b
 
d5ce935
cc6bd3b
 
 
 
 
 
d5ce935
cc6bd3b
 
 
 
 
 
fae0e51
cc6bd3b
 
 
 
 
 
 
910ae58
cc6bd3b
 
910ae58
cc6bd3b
 
 
 
 
910ae58
cc6bd3b
fae0e51
cc6bd3b
 
fae0e51
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
49
50
51
52
from typing import Dict, Any

from args import Args
from graph import State
from graph_builder import GraphBuilder


# Maximum number of interactions between Assistant and Manager
MAX_INTERACTIONS = 5
# Maximum depth of recursion for Manager
MAX_DEPTH = 2
# For both Assistant and Manager:
TEMPERATURE = 0.7
MAX_TOKENS = 2000


class Alfred:

    def __init__(self):
        print("Agent initialized.")

        self.graph_builder = GraphBuilder()
        self.agent_graph = self.graph_builder.build_agent_graph()

    async def __call__(self, question: str) -> str:
        print(f"Agent received question (first 50 chars): {question[:50]}...")
        result = await self.process_query(question)
        response = result["final_response"]
        print(f"Agent processed the response: {response}")

        return response

    async 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": [],
            "nr_interactions": 0,
            "final_response": None
        }

        result = await self.agent_graph.ainvoke(initial_state)
        return result