OpenParable
Skip to content
← Back to skills

Golem Call Another Agent Moonbit

Agent Building
golem-call-another-agent-moonbit

Golem Call Another Agent Moonbit is an Agent Skill for agent building published in the golemcloud/golem repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Calling another agent and awaiting the result in a MoonBit Golem project. Use when the user asks about agent-to-agent RPC, calling remote agents, or inter-component communication.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/golemcloud/golem/blob/HEAD/golem-skills/skills/moonbit/golem-call-another-agent-moonbit/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/golem-call-another-agent-moonbit, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Calling Another Agent (MoonBit)

Overview

The #derive.agent code generation tool auto-generates a <AgentName>Client struct for each agent, enabling agent-to-agent communication via RPC. An awaited call blocks the calling agent until the target agent returns a result.

Getting a Client (Scoped)

Use <AgentName>Client::scoped(...) with the target agent's constructor parameters and a callback. The client is automatically dropped when the callback returns:

CounterClient::scoped("my-counter", fn(counter) raise @common.AgentError {
  counter.increment()
  counter.increment()
  let value = counter.get_value()
  value
})

This is the recommended pattern — it ensures the client resource is cleaned up automatically.

Note: agents with no constructor parameters omit the parameter from scoped / get.

Getting a Client (Manual)

Use <AgentName>Client::get(...) for manual lifecycle management. You must call client.drop() when done:

let counter = CounterClient::get("my-counter")
counter.increment()
let value = counter.get_value()
counter.drop()  // must call drop when done

This does not create the agent — the agent is created implicitly on its first invocation. If it already exists, you get a handle to the existing instance.

Awaited Call

Call a method and block until the result returns:

CounterClient::scoped("my-counter", fn(counter) raise @common.AgentError {
  counter.increment()
  let count = counter.get_value()
  count
})

The calling agent blocks until the target agent processes the request and returns. This is the standard RPC pattern.

Passing Complex Types

Agent methods accept custom types defined in your agent code:

TaskManagerClient::scoped(fn(tm) raise @common.AgentError {
  let count = tm.add_task({
    title: "Build RPC support",
    priority: High,
    description: Some("Implement agent-to-agent communication"),
  })
  let high_tasks = tm.get_by_priority(High)
  let _ = high_tasks
  count
})

Phantom Agents

To create multiple distinct instances with the same constructor parameters, use phantom agents. See the golem-multi-instance-agent-moonbit skill.

Cross-Component RPC

When calling agents defined in a different component, the generated client type is available after running golem build — the build step generates bridge SDK code for inter-component dependencies declared in golem.yaml.

Avoiding Deadlocks

Never create RPC cycles where A awaits B and B awaits A — this deadlocks both agents. Use trigger_ (fire-and-forget) to break cycles. See the golem-fire-and-forget-moonbit skill.