Skip to Content
How-To GuidesMoonBitFire-and-Forget Agent Invocation (MoonBit)

Fire-and-Forget Agent Invocation (MoonBit)

Overview

A fire-and-forget call enqueues a method invocation on the target agent and returns immediately without waiting for the result. The target agent processes the invocation asynchronously. This is for agent-to-agent calls from code, not from the CLI.

For CLI fire-and-forget, see the golem-trigger-agent-moonbit guide.

Usage

Every method on the auto-generated AgentClient has a corresponding trigger_ variant. Use AgentClient::scoped to obtain a client instance, then call the trigger_ method:

AgentClient::scoped("my-counter", fn(client) raise @common.AgentError { client.trigger_increment() })

With arguments:

DataProcessorClient::scoped("pipeline-1", fn(client) raise @common.AgentError { client.trigger_process_batch(batch_data) })

When to Use

  • Breaking RPC cycles: If agent A calls agent B and B needs to call back to A, use trigger_ for the callback to avoid deadlocks
  • Background work: Enqueue work on another agent without blocking the current agent
  • Fan-out: Trigger work on many agents in parallel without waiting for all results
  • Event-driven patterns: Notify other agents about events without coupling to their processing time

Example: Breaking a Deadlock

// In AgentA — calls AgentB and waits AgentBClient::scoped("b1", fn(client) raise @common.AgentError { let result = client.do_work(data) // OK: awaited call // ... }) // In AgentB — notifies AgentA without waiting (would deadlock if awaited) AgentAClient::scoped("a1", fn(client) raise @common.AgentError { client.trigger_on_work_done(result) // OK: fire-and-forget })

Example: Fan-Out

let regions : Array[String] = ["us-east", "us-west", "eu-central"] for region in regions { RegionProcessorClient::scoped(region, fn(client) raise @common.AgentError { client.trigger_run_report(report_id) }) }

CLI Equivalent

From the command line, use --trigger:

golem agent invoke --trigger 'CounterAgent("my-counter")' increment

See the golem-trigger-agent-moonbit skill for full CLI details.

Last updated on