-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleGraph.py
More file actions
72 lines (59 loc) · 2.4 KB
/
Copy pathexampleGraph.py
File metadata and controls
72 lines (59 loc) · 2.4 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
"""Example conversation with an agent backed by graph memory.
Run from the repo root:
python exampleGraph.py
The conversation is interactive. Type your message and the agent
responds. Type an empty line to exit. The agent's memory persists
across runs in the Neo4j database; use scripts/clear_graph.py to
wipe it.
"""
import argparse
import os
from openai import AzureOpenAI, OpenAI
from agents.GraphAgent import GraphAgent
from agents.HumanAgent import HumanAgent
from conversations.SingleAgentConversation import SingleAgentConversation
from graph.connection import make_driver
def main() -> None:
parser = argparse.ArgumentParser(description="Example conversation with a graph-memory agent.")
parser.add_argument("--name", "-n", type=str, default=None, help="Conversation name. Defaults to a fresh timestamped session each run, so the YAML tape is not replayed. Pass an existing name (or 'latest') to resume.")
parser.add_argument("--enact", action="store_true", help="Re-enact the conversation history.")
parser.add_argument("--override", "-x", action="store_true", help="Override an existing conversation.")
args = parser.parse_args()
client = AzureOpenAI(
azure_endpoint=os.environ["CHATUIT_BASE_URL"],
api_key=os.environ["CHATUIT_API_KEY"],
api_version="2024-02-15-preview",
)
# Optional: route extraction to standard OpenAI for access to a
# stronger model (gpt-4.1). Chat and embeddings stay on Azure.
# If OPENAI_API_KEY is not set, extraction falls back to the chat
# client/model.
extraction_client = None
extraction_model = None
if os.environ.get("OPENAI_API_KEY"):
extraction_client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
extraction_model = "gpt-4.1"
driver = make_driver()
try:
agent = GraphAgent(
name="A",
client=client,
driver=driver,
model="gpt-4.1-mini",
extraction_client=extraction_client,
extraction_model=extraction_model,
)
human = HumanAgent("H")
conv = SingleAgentConversation(
agent=agent,
human_agent=human,
output_dir="output/exampleGraph",
conversation_name=args.name,
override=args.override,
)
conv.start(enact=args.enact)
finally:
driver.close()
if __name__ == "__main__":
main()