MCPcopy
hub / github.com/HKUDS/DeepCode / agent

Function agent

nanobot/nanobot/cli/commands.py:441–539  ·  view source on GitHub ↗

Interact with the agent directly.

(
    message: str = typer.Option(None, "--message", "-m", help="Message to send to the agent"),
    session_id: str = typer.Option("cli:default", "--session", "-s", help="Session ID"),
    markdown: bool = typer.Option(
        True, "--markdown/--no-markdown", help="Render assistant output as Markdown"
    ),
    logs: bool = typer.Option(
        False, "--logs/--no-logs", help="Show nanobot runtime logs during chat"
    ),
)

Source from the content-addressed store, hash-verified

439
440@app.command()
441def agent(
442 message: str = typer.Option(None, "--message", "-m", help="Message to send to the agent"),
443 session_id: str = typer.Option("cli:default", "--session", "-s", help="Session ID"),
444 markdown: bool = typer.Option(
445 True, "--markdown/--no-markdown", help="Render assistant output as Markdown"
446 ),
447 logs: bool = typer.Option(
448 False, "--logs/--no-logs", help="Show nanobot runtime logs during chat"
449 ),
450):
451 """Interact with the agent directly."""
452 from loguru import logger
453
454 from nanobot.agent.loop import AgentLoop
455 from nanobot.bus.queue import MessageBus
456 from nanobot.config.loader import load_config
457
458 config = load_config()
459
460 bus = MessageBus()
461 provider = _make_provider(config)
462
463 if logs:
464 logger.enable("nanobot")
465 else:
466 logger.disable("nanobot")
467
468 agent_loop = AgentLoop(
469 bus=bus,
470 provider=provider,
471 workspace=config.workspace_path,
472 brave_api_key=config.tools.web.search.api_key or None,
473 exec_config=config.tools.exec,
474 restrict_to_workspace=config.tools.restrict_to_workspace,
475 )
476
477 # Show spinner when logs are off (no output to miss); skip when logs are on
478 def _thinking_ctx():
479 if logs:
480 from contextlib import nullcontext
481
482 return nullcontext()
483 return console.status("[dim]nanobot is thinking...[/dim]", spinner="dots")
484
485 if message:
486 # Single message mode
487 async def run_once():
488 with _thinking_ctx():
489 response = await agent_loop.process_direct(message, session_id)
490 _print_agent_response(response, render_markdown=markdown)
491
492 asyncio.run(run_once())
493 else:
494 # Interactive mode
495 _enable_line_editing()
496 console.print(
497 f"{__logo__} Interactive mode (type [bold]exit[/bold] or [bold]Ctrl+C[/bold] to quit)\n"
498 )

Callers

nothing calls this directly

Calls 10

load_configFunction · 0.90
MessageBusClass · 0.90
AgentLoopClass · 0.90
_make_providerFunction · 0.85
run_onceFunction · 0.85
_enable_line_editingFunction · 0.85
run_interactiveFunction · 0.85
enableMethod · 0.80
disableMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected