MCPcopy Create free account
hub / github.com/vercel/examples / run_agent_flow

Function run_agent_flow

python/vibe-coding-ide/backend/src/agent/agent.py:86–222  ·  view source on GitHub ↗

Run the agent and stream tool progress as SSE chunks.

(
    payload: dict[str, Any], task_id: str, oidc_token: str | None = None
)

Source from the content-addressed store, hash-verified

84
85
86async def run_agent_flow(
87 payload: dict[str, Any], task_id: str, oidc_token: str | None = None
88) -> AsyncGenerator[str, None]:
89 """Run the agent and stream tool progress as SSE chunks."""
90 try:
91 logger.info(
92 "run[%s] start model=%s project_files=%d history=%d",
93 task_id,
94 payload.get("model"),
95 len(payload.get("project", {})),
96 len(payload.get("message_history", [])),
97 )
98 except Exception:
99 pass
100
101 # Filter project using ignore patterns from .agentignore/.gitignore and defaults
102 original_project = payload.get("project", {}) or {}
103 is_ignored = make_ignore_predicate(original_project)
104 filtered_project = {
105 p: c
106 for p, c in original_project.items()
107 if (not is_ignored(p)) or (p in {".gitignore", ".agentignore"})
108 }
109
110 base_payload = {
111 "user_id": payload["user_id"],
112 "project_id": payload["project_id"],
113 "query": payload["query"],
114 "project": filtered_project,
115 "message_history": payload.get("message_history", []),
116 "model": payload.get("model"),
117 }
118
119 history = payload.get("message_history", [])
120 assistant_only = [
121 m["content"]
122 for m in history
123 if m.get("role") == "assistant" and m.get("content")
124 ]
125 input_text = build_project_input(
126 payload["query"], filtered_project, history or assistant_only
127 )
128
129 context = IDEContext(project=filtered_project, base_payload=base_payload)
130 # Keep run store in sync with filtered project so resume tokens remain small
131 try:
132 import asyncio
133
134 coro = update_run_project(task_id, filtered_project)
135 if asyncio.get_event_loop().is_running():
136 asyncio.create_task(coro)
137 else:
138 asyncio.run(coro)
139 except Exception:
140 pass
141
142 selected_model = payload.get("model")
143 agent_instance = create_ide_agent(selected_model, oidc_token)

Callers 1

event_generatorFunction · 0.90

Calls 11

make_ignore_predicateFunction · 0.90
build_project_inputFunction · 0.90
IDEContextClass · 0.90
update_run_projectFunction · 0.90
sse_formatFunction · 0.90
emit_eventFunction · 0.90
tool_started_sseFunction · 0.90
tool_completed_sseFunction · 0.90
is_ignoredFunction · 0.85
create_ide_agentFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected