MCPcopy Index your code
hub / github.com/google/adk-python / run_interactively

Function run_interactively

src/google/adk/cli/cli.py:187–265  ·  view source on GitHub ↗
(
    root_agent_or_app: Union[LlmAgent, App],
    artifact_service: BaseArtifactService,
    session: Session,
    session_service: BaseSessionService,
    credential_service: BaseCredentialService,
    memory_service: Optional[BaseMemoryService] = None,
    timeout: Optional[str] = None,
    jsonl: bool = False,
)

Source from the content-addressed store, hash-verified

185
186
187async def run_interactively(
188 root_agent_or_app: Union[LlmAgent, App],
189 artifact_service: BaseArtifactService,
190 session: Session,
191 session_service: BaseSessionService,
192 credential_service: BaseCredentialService,
193 memory_service: Optional[BaseMemoryService] = None,
194 timeout: Optional[str] = None,
195 jsonl: bool = False,
196) -> None:
197 app = _to_app(root_agent_or_app, session.app_name)
198 runner = Runner(
199 app=app,
200 artifact_service=artifact_service,
201 session_service=session_service,
202 memory_service=memory_service,
203 credential_service=credential_service,
204 )
205
206 next_message = None
207 resume_invocation_id = None
208 while True:
209 if next_message is None:
210 query = input('[user]: ')
211 if not query or not query.strip():
212 continue
213 if query == 'exit':
214 break
215 next_message = types.Content(role='user', parts=[types.Part(text=query)])
216
217 collected_events = []
218 invocation_id = None
219
220 async def run_and_print():
221 nonlocal invocation_id
222 async with Aclosing(
223 runner.run_async(
224 user_id=session.user_id,
225 session_id=session.id,
226 new_message=next_message,
227 invocation_id=resume_invocation_id,
228 )
229 ) as agen:
230 async for event in agen:
231 collected_events.append(event)
232 if getattr(event, 'invocation_id', None):
233 invocation_id = event.invocation_id
234 _print_event(event, jsonl=jsonl, session_id=session.id)
235
236 try:
237 if timeout:
238 seconds = _parse_timeout(timeout)
239 await asyncio.wait_for(run_and_print(), timeout=seconds)
240 else:
241 await run_and_print()
242 except asyncio.TimeoutError:
243 click.secho(
244 f'Error: Command timed out after {timeout}', fg='red', err=True

Callers 1

run_cliFunction · 0.85

Calls 9

closeMethod · 0.95
_to_appFunction · 0.85
RunnerClass · 0.85
_parse_timeoutFunction · 0.85
run_and_printFunction · 0.85
stripMethod · 0.80
extendMethod · 0.45

Tested by

no test coverage detected