File size: 1,880 Bytes
6cbca40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import TypedDict
from src.config.llm import model
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.prebuilt import create_react_agent
from langgraph_swarm import create_handoff_tool, create_swarm
from .prompt import roleplay_prompt, guiding_prompt


class State(TypedDict):
    pass


def create_agents(scenario, checkpointer=InMemorySaver()):

    roleplay_agent = create_react_agent(
        model,
        [
            create_handoff_tool(
                agent_name="Guiding Agent",
                description="Hand off to Guiding Agent when user shows signs of needing help, guidance, or struggles with communication",
            ),
        ],
        prompt=roleplay_prompt.format(
            scenario_title=scenario["scenario_title"],
            scenario_description=scenario["scenario_description"],
            scenario_context=scenario["scenario_context"],
            your_role=scenario["your_role"],
            key_vocabulary=scenario["key_vocabulary"],
        ),
        name="Roleplay Agent",
    )

    guiding_agent = create_react_agent(
        model,
        [
            create_handoff_tool(
                agent_name="Roleplay Agent",
                description="Hand off back to Roleplay Agent when user is ready for scenario practice and shows improved confidence",
            ),
        ],
        prompt=guiding_prompt.format(
            scenario_title=scenario["scenario_title"],
            scenario_description=scenario["scenario_description"],
            scenario_context=scenario["scenario_context"],
            your_role=scenario["your_role"],
            key_vocabulary=scenario["key_vocabulary"],
        ),
        name="Guiding Agent",
    )

    workflow = create_swarm(
        [roleplay_agent, guiding_agent], default_active_agent="Roleplay Agent"
    )

    return workflow.compile(checkpointer)