-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
62 lines (49 loc) · 2.1 KB
/
Copy pathagent.py
File metadata and controls
62 lines (49 loc) · 2.1 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
"""Append-only prompt buffer tracking and ReAct state management."""
S0 = (
"User Query: Find if Batman has a hidden connection to Spider-Man through an intermediate contact. "
"Available Tools: Graph_Lookup(character_name) which returns immediate neighbors."
)
T0_A0 = 'I need to check who Batman is directly connected to first. Graph_Lookup("Batman")'
O1 = 'Neighbors of Batman = [Superman]'
T1_A1 = (
'Batman connects to Superman. Now I need to see if Superman connects closer to Spider-Man or to someone else who does. '
'Graph_Lookup("Superman")'
)
O2 = 'Neighbors of Superman = [Iron Man]'
T2_A2 = (
'Superman connects to Iron Man. Let me check Iron Man\'s connections. '
'Graph_Lookup("Iron Man")'
)
O3 = 'Neighbors of Iron Man = [Spider-Man]'
T3 = (
'Iron Man connects directly to Spider-Man. Path found: Batman -> Superman -> Iron Man -> Spider-Man.'
)
R = (
'Yes, Batman has a hidden connection to Spider-Man. '
'The path is exactly: Batman -> Superman -> Iron Man -> Spider-Man.'
)
BUNDLE_STEP_5 = f"{T2_A2} {O3} {T3} {R}"
def count_words(text: str) -> int:
"""Count words by whitespace separation while ignoring punctuation tokens.
This preserves tool call identifiers like Graph_Lookup(character_name) as a single token.
"""
cleaned = text.replace("->", " ")
for char in "\n\t\r.,:;":
cleaned = cleaned.replace(char, " ")
for char in "[]()\"'":
cleaned = cleaned.replace(char, "")
return len([token for token in cleaned.split() if token])
def build_context_sequence() -> list[str]:
"""Return the append-only text sequence for the ReAct execution trace."""
return [S0, T0_A0, O1, T1_A1, O2, BUNDLE_STEP_5]
def compute_step_counts(sequence: list[str]) -> tuple[list[int], list[int]]:
"""Return per-step word counts and cumulative word volumes."""
step_counts: list[int] = []
cumulative_volumes: list[int] = []
total = 0
for item in sequence:
current = count_words(item)
step_counts.append(current)
total += current
cumulative_volumes.append(total)
return step_counts, cumulative_volumes