Spaces:
Sleeping
Sleeping
mriusero
commited on
Commit
·
05dd2f4
1
Parent(s):
9ec3492
feat: cycles
Browse files- src/agent/stream.py +4 -4
src/agent/stream.py
CHANGED
@@ -42,12 +42,12 @@ async def respond(message, history=None, state=None):
|
|
42 |
history.append(ChatMessage(role="assistant", content="", metadata={"title": "Thinking...", "status": "pending", 'id': state["cycle"]}))
|
43 |
yield history
|
44 |
else:
|
|
|
45 |
messages = state["chat"] + [
|
46 |
{"role": "user", "content": message},
|
47 |
{"role": "assistant", "content": "THINK: Let's start thinking, ", "prefix": True}
|
48 |
]
|
49 |
-
history.append(ChatMessage(role="assistant", content=""))
|
50 |
-
history[-1] = (ChatMessage(role="assistant", content="", metadata={"title": "Thinking...", "status": "pending", 'id': state["cycle"]}))
|
51 |
yield history
|
52 |
|
53 |
phase_order = ["think", "act", "observe", "final"]
|
@@ -91,7 +91,7 @@ async def respond(message, history=None, state=None):
|
|
91 |
phases = extract_phases(full)
|
92 |
buffer = phases.get(current_phase, "")
|
93 |
if current_phase == "think":
|
94 |
-
history[-1] = ChatMessage(role="assistant", content=buffer, metadata={"title": "Thinking...", "status": "pending", "id": state['cycle']
|
95 |
elif current_phase == "act":
|
96 |
history[-1] = ChatMessage(role="assistant", content=buffer, metadata={"title": "Acting...", "status": "pending", "id": state['cycle']+1, 'parent_id': state["cycle"]})
|
97 |
elif current_phase == "observe":
|
@@ -161,7 +161,7 @@ async def respond(message, history=None, state=None):
|
|
161 |
final_text = phases.get("final", "")
|
162 |
|
163 |
if observe_text:
|
164 |
-
history[-1] = ChatMessage(role="assistant", content=observe_text, metadata={"title": "
|
165 |
messages = [msg for msg in messages if not msg.get("prefix")]
|
166 |
messages.append({
|
167 |
"role": "assistant",
|
|
|
42 |
history.append(ChatMessage(role="assistant", content="", metadata={"title": "Thinking...", "status": "pending", 'id': state["cycle"]}))
|
43 |
yield history
|
44 |
else:
|
45 |
+
history = []
|
46 |
messages = state["chat"] + [
|
47 |
{"role": "user", "content": message},
|
48 |
{"role": "assistant", "content": "THINK: Let's start thinking, ", "prefix": True}
|
49 |
]
|
50 |
+
history.append(ChatMessage(role="assistant", content="", metadata={"title": "Thinking...", "status": "pending", 'id': state["cycle"]}))
|
|
|
51 |
yield history
|
52 |
|
53 |
phase_order = ["think", "act", "observe", "final"]
|
|
|
91 |
phases = extract_phases(full)
|
92 |
buffer = phases.get(current_phase, "")
|
93 |
if current_phase == "think":
|
94 |
+
history[-1] = ChatMessage(role="assistant", content=buffer, metadata={"title": "Thinking...", "status": "pending", "id": state['cycle']})
|
95 |
elif current_phase == "act":
|
96 |
history[-1] = ChatMessage(role="assistant", content=buffer, metadata={"title": "Acting...", "status": "pending", "id": state['cycle']+1, 'parent_id': state["cycle"]})
|
97 |
elif current_phase == "observe":
|
|
|
161 |
final_text = phases.get("final", "")
|
162 |
|
163 |
if observe_text:
|
164 |
+
history[-1] = ChatMessage(role="assistant", content=observe_text, metadata={"title": "Thoughts", "status": "done", "id": state['cycle']+2, 'parent_id': state["cycle"]})
|
165 |
messages = [msg for msg in messages if not msg.get("prefix")]
|
166 |
messages.append({
|
167 |
"role": "assistant",
|