prefect.cli.agent
Command line interface for working with agent services
start
async
Start an agent process.
Source code in prefect/cli/agent.py
@agent_app.command()
async def start(
work_queue: str = typer.Argument(
..., help="A work queue name or ID for the agent to pull from."
),
hide_welcome: bool = typer.Option(False, "--hide-welcome"),
api: str = SettingsOption(PREFECT_API_URL),
):
"""
Start an agent process.
"""
try:
work_queue_id = UUID(work_queue)
work_queue_name = None
except:
work_queue_id = None
work_queue_name = work_queue
if not hide_welcome:
if api:
app.console.print(f"Starting agent connected to {api}...")
else:
app.console.print("Starting agent with ephemeral API...")
running = True
async with OrionAgent(
work_queue_id=work_queue_id,
work_queue_name=work_queue_name,
) as agent:
if not hide_welcome:
app.console.print(ascii_name)
app.console.print(
f"Agent started! Looking for work from queue '{work_queue}'..."
)
while running:
try:
await agent.get_and_submit_flow_runs()
except KeyboardInterrupt:
running = False
await anyio.sleep(PREFECT_AGENT_QUERY_INTERVAL.value())
app.console.print("Agent stopped!")