Creating a Golem Agent Instance with `golem agent create`
Both golem and golem-cli can be used — all commands below work with either binary.
Usage
golem agent create <AGENT_KEY> [--keyed] [OPTIONS]
golem agent upsert <AGENT_KEY>
golem agent create creates a new agent instance without invoking any method on it. The agent is initialized with its constructor parameters and starts in an idle state, ready to receive invocations. The command prints the new agent's agent ID, a UUID that Golem issues. If the agent's component has not been deployed yet and the CLI is run from an application directory, it will automatically build and deploy the component first.
- Without
--keyed, each call creates a new agent without a key, with a new agent ID. Such an agent is reachable only by its ID:AgentTypeName[<agent-id>]or the bare<agent-id>. - With
--keyed, it creates the keyed agent of the constructor parameters: the agent that the keyAgentTypeName(params)addresses. It fails when that keyed agent already exists.
golem agent upsert gets the keyed agent of the constructor parameters and creates it when it does not exist. It takes no environment variables or configuration.
golem agent invoke with a key also creates the keyed agent on first call. Use golem agent create when you need to set environment variables or configuration at creation time, or when you want an agent without a key.
Agent Key Format
Both commands take a key: the agent type and its constructor parameters:
AgentTypeName(param1, param2, ...)
The key can optionally be prefixed with environment or application paths:
| Format | Description |
|--------|-------------|
| AgentTypeName(params) | Key without a prefix |
| env/AgentTypeName(params) | Environment-specific |
| app/env/AgentTypeName(params) | Application and environment-specific |
| account/app/env/AgentTypeName(params) | Account, application, and environment-specific |
For agents with no constructor parameters, use empty parentheses: AgentTypeName().
Examples
Create an agent without a key
golem agent create 'MyAgent()'
# Invoke it by the agent ID that the command prints
golem agent invoke 'MyAgent[<agent-id>]' <FUNCTION_NAME>
Create the keyed agent
golem agent create --keyed 'ChatRoom("general")'
# Invoke it by its key
golem agent invoke 'ChatRoom("general")' <FUNCTION_NAME>
Get or create the keyed agent
golem agent upsert 'ChatRoom("general")'
Retry a create safely
# The same idempotency key returns the agent of the first create
golem agent create -i create-42 'MyAgent()'
Create an agent with environment variables
golem agent create 'MyAgent("user-123")' --env API_KEY=sk-abc123 --env LOG_LEVEL=debug
Create an agent with configuration
golem agent create 'MyAgent()' --config maxRetries=5 --config timeoutSeconds=30
Create an agent in a specific environment
golem agent create 'staging/MyAgent("user-123")'
Combine environment variables and configuration
golem agent create 'OrderProcessor("us-east")' \
--env DATABASE_URL=postgres://... \
--config batchSize=100 \
--config retryPolicy.maxAttempts=3
Available Options
The options of golem agent create (golem agent upsert takes none):
| Option | Description |
|--------|-------------|
| --keyed | Create the keyed agent of the constructor parameters; fail when it already exists |
| -i, --idempotency-key <KEY> | Idempotency key of the create; a create retried with the same key returns the agent of the first create |
| -e, --env <ENV=VAL> | Environment variables visible to the agent (can be repeated) |
| -c, --config <PATH=VALUE> | Configuration entries for the agent, using dot-separated paths (can be repeated). Only configuration declared by the agent can be provided. If not provided, the default from the manifest (agents.*.config) is used. |
Auto-Deploy
If the agent's component has not been deployed yet and the CLI is run from an application directory, golem agent create and golem agent upsert will automatically build and deploy the component before creating the agent.
Value Syntax
The key parameters use Scala syntax:
- Field names use
camelCasewith=separator - Options:
Some(value)/None - Records:
MyRecord(fieldOne = 1, fieldTwo = "hello") - Enums/Variants:
MyEnum.VariantNameorMyEnum.VariantName(value) - Tuples:
(1, "hello")orTuple1(value)for single-element - Results:
WitResult.Ok(value)/WitResult.Err(value)
golem agent create 'UserManager(MyConfig(region = "us-east", maxConnections = Some(10)))'
When to Use `golem agent create` vs `golem agent invoke`
- Use
golem agent createwhen you need to pre-create an agent with specific environment variables or configuration before any invocation, or when you need an agent without a key. - Use
golem agent invokewith a key when you want to call a method — the keyed agent is created automatically on first invocation if it doesn't exist. - A keyed agent can be invoked later by its key. An agent without a key can be invoked only by the agent ID that
golem agent createprints.