Fix /api/agent-stream: use build_agent_prompt, accumulate response_text, call parse_agent_commands
This commit is contained in:
parent
c6ce8a873c
commit
46a77c7800
1 changed files with 12 additions and 16 deletions
28
app.py
28
app.py
|
|
@ -2495,22 +2495,11 @@ def agent_stream():
|
||||||
selected_agent = delegate_to_agent(prompt)
|
selected_agent = delegate_to_agent(prompt)
|
||||||
agent_info = AGENTS.get(selected_agent, {})
|
agent_info = AGENTS.get(selected_agent, {})
|
||||||
agent_name = agent_info.get('name', selected_agent)
|
agent_name = agent_info.get('name', selected_agent)
|
||||||
system_prompt = get_agent_prompt(selected_agent)
|
|
||||||
|
|
||||||
kb_file = os.path.join(os.path.dirname(__file__), 'agents', 'orchestrator', 'knowledge', 'diversityball_knowledge.md')
|
full_prompt = build_agent_prompt(selected_agent, prompt)
|
||||||
kb_content = ""
|
if not full_prompt:
|
||||||
if os.path.exists(kb_file):
|
yield f"data: {json.dumps({'type': 'error', 'message': f'Kein System-Prompt für Agent {selected_agent}'})}\n\n"
|
||||||
with open(kb_file, 'r', encoding='utf-8') as f:
|
return
|
||||||
kb_content = f.read()
|
|
||||||
|
|
||||||
full_prompt = f"""## Wissensdatenbank (Diversity-Ball):
|
|
||||||
{kb_content}
|
|
||||||
|
|
||||||
## System-Prompt des Agenten ({agent_name}):
|
|
||||||
{system_prompt}
|
|
||||||
|
|
||||||
## Deine Aufgabe:
|
|
||||||
{prompt}"""
|
|
||||||
|
|
||||||
# Sofort Agent-Info senden
|
# Sofort Agent-Info senden
|
||||||
yield f"data: {json.dumps({'type': 'agent_selected', 'agent': agent_name, 'agent_key': selected_agent})}\n\n"
|
yield f"data: {json.dumps({'type': 'agent_selected', 'agent': agent_name, 'agent_key': selected_agent})}\n\n"
|
||||||
|
|
@ -2530,7 +2519,8 @@ def agent_stream():
|
||||||
cwd=work_dir # Agent arbeitet in seinem work-Verzeichnis
|
cwd=work_dir # Agent arbeitet in seinem work-Verzeichnis
|
||||||
)
|
)
|
||||||
|
|
||||||
# Jede Zeile sofort aus opencode lesen und streamen
|
# Jede Zeile sofort aus opencode lesen, streamen und akkumulieren
|
||||||
|
response_text = ""
|
||||||
for line in proc.stdout:
|
for line in proc.stdout:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line:
|
if not line:
|
||||||
|
|
@ -2540,11 +2530,17 @@ def agent_stream():
|
||||||
if event_data.get('part', {}).get('type') == 'text':
|
if event_data.get('part', {}).get('type') == 'text':
|
||||||
text = event_data['part'].get('text', '')
|
text = event_data['part'].get('text', '')
|
||||||
if text:
|
if text:
|
||||||
|
response_text += text
|
||||||
yield f"data: {json.dumps({'type': 'response_chunk', 'text': text})}\n\n"
|
yield f"data: {json.dumps({'type': 'response_chunk', 'text': text})}\n\n"
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
|
||||||
|
# XML-Kommandos aus der gesammelten Antwort ausführen
|
||||||
|
if response_text:
|
||||||
|
parse_agent_commands(selected_agent, response_text)
|
||||||
|
|
||||||
yield f"data: {json.dumps({'type': 'complete', 'message': '✓ Fertig'})}\n\n"
|
yield f"data: {json.dumps({'type': 'complete', 'message': '✓ Fertig'})}\n\n"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue