Overview
Thesam task command sends tasks to the webui gateway and receives streaming responses via Server-Sent Events (SSE).
Syntax
Description
The task command provides two ways to interact with SAM agents:- send: Send tasks to a running SAM instance
- run: Start SAM, send a task, and stop (all-in-one command)
Subcommands
sam task send
Send a task to a running webui gateway and stream the response.Syntax
Arguments
The prompt text to send to the agent.
Options
Base URL of the webui gateway.Can be set via environment variable:
SAM_WEBUI_URLTarget agent name.Can be set via environment variable:
SAM_AGENTSession ID for context continuity. Generates new if not provided.
Bearer token for authentication.Can be set via environment variable:
SAM_AUTH_TOKENFile(s) to attach. Can be used multiple times.Example:
-f doc1.pdf -f doc2.txtTimeout in seconds for SSE connection.
Output directory for artifacts and logs.Default:
/tmp/sam-task-{taskId}Suppress streaming output, only show final result.
Do not fetch the STIM file on completion.
Enable debug output.
Examples
Basic usage:Output
Normal mode (streaming):sam task run
Start SAM, send a task, stream the response, and stop.Syntax
Arguments
The prompt text to send to the agent.
Options
Includes all options fromsam task send plus:
YAML config files or directories. Can be used multiple times.Defaults to
configs/ directory.File name(s) to exclude from configs (e.g.,
-s my_agent.yaml).Timeout in seconds for task execution (note: different default from send).
Timeout in seconds for agent readiness.
Use system environment variables only; do not load
.env file.Examples
Basic usage with default configs:Output
Agent Readiness
Thesam task run command implements an agent readiness algorithm:
- Poll
/api/v1/agentCardsuntil at least one agent is detected - Wait 2 seconds for stabilization (allows all agents to register)
- Poll again to get the final agent list
- Verify the target agent exists
- Proceed with task execution
Session Management
Sessions allow multi-turn conversations with agents:- Auto-generated if not provided
- Displayed in the output after each task
- Used to maintain conversation context
File Attachments
Attach files to provide context to agents:Artifacts
Agents can generate artifacts (files, images, data) during task execution:- Automatically downloaded to output directory
- Output directory structure:
STIM Files
STIM (Solace Task Interaction Model) files capture the complete task interaction:- Contains full request/response history
- Includes metadata, artifacts, and events
- Saved as
{taskId}.stimin output directory - Skip generation with
--no-stimflag
Authentication
For protected gateways, provide a bearer token:Exit Codes
0: Task completed successfully1: Error (connection failed, agent not found, timeout, etc.)
Implementation Details
Implemented in:- Send:
/home/daytona/workspace/source/cli/commands/task_cmd/send.py - Run:
/home/daytona/workspace/source/cli/commands/task_cmd/run.py
- SSE (Server-Sent Events) for streaming responses
- httpx for async HTTP operations
- SAMRunner for process management (run command)
Troubleshooting
Error: Failed to connect
Cause: Gateway not running or wrong URL Solution:Error: Agent not found
Cause: Specified agent doesn’t exist Solution:Timeout waiting for agents
Cause: Agents taking too long to start Solution:See Also
- sam run - Run SAM application
- sam add agent - Create new agents
- sam tools - List available agent tools