Skip to Content
How-To GuidesScalaCall a Golem tool from Scala

Call a Golem tool from Scala

@toolDefinition generates <Tool>Client. Construct it with the generated factory and call the typed asynchronous methods:

import golem.tool.ToolError import scala.concurrent.Future val client: EchoClient = EchoClient() val result: Future[Either[ToolError[Nothing], String]] = client.echo("hello")

Use the exact generated signature: a command with declared errors uses the error type declared by the tool method instead of Nothing. Commands without stdout or stderr, including stdin-only commands, return Future[Either[ToolError[E], A]]; stdin is a ToolInputStream parameter. A command with either output returns Either[ToolError[E], ToolInvocation[E, A]], whose invocation exposes the result and independent stdout/stderr streams. Drain both outputs concurrently. Handle ToolError.Tool separately from protocol failures. Never edit generated clients.