### Run simple_agent example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/running-examples.mdx Run the simple_agent example from the examples/ directory. Requires completing the Configuration setup first. ```bash cd examples go run ./simple_agent "Hello, what can you do?" ``` -------------------------------- ### Run the Temporal client example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/temporal-client.mdx Starts Temporal infrastructure and runs the example agent with the Temporal runtime. Requires Temporal to be running and environment variables set in `.env`. ```bash task infra:temporal:up && task infra:temporal:wait AGENT_RUNTIME=temporal go run ./agent_with_temporal_client "Hello, what can you do?" ``` -------------------------------- ### Run Weaviate memory example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/memory.mdx Start the Weaviate backend, run the memory example, and then tear down the infrastructure. Requires EMBEDDING_OPENAI_APIKEY in .env before starting. ```bash task infra:weaviate:up # EMBEDDING_OPENAI_APIKEY must be in .env before up go run ./agent_with_memory/weaviate task infra:weaviate:down # when finished ``` -------------------------------- ### Weaviate Infrastructure Setup Commands Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_memory/README.md Commands to start and stop the Weaviate infrastructure using task. Run 'up' before the example, 'down' when finished. ```bash cd examples task infra:weaviate:up task infra:weaviate:down # when finished ``` -------------------------------- ### Run pgvector memory example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/memory.mdx Start the pgvector backend, run the memory example, and then tear down the infrastructure. ```bash task infra:pgvector:up go run ./agent_with_memory/pgvector task infra:pgvector:down # when finished ``` -------------------------------- ### Run the A2A server example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/a2a-server.mdx Starts the example server from the examples/ directory. The process prints the base URL and agent card URL to stderr and blocks until Ctrl+C is pressed. Defaults to localhost:9999, overridable via A2A_SERVER_HOST and A2A_SERVER_PORT. ```bash go run ./agent_with_a2a_server ``` -------------------------------- ### Weaviate setup commands Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/retrieval.mdx Start the Weaviate infrastructure, run the Weaviate agent with a sample question, and then tear down the infrastructure. The question should be concrete and aligned with the sample KB (e.g., return policy). ```bash task infra:weaviate:up ``` ```bash go run ./agent_with_retriever/weaviate "What is the return policy?" ``` ```bash task infra:weaviate:down ``` -------------------------------- ### Run the MCP client example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/mcp-client.mdx Run the example from the examples directory. The second command passes a prompt to list available tools. ```bash go run ./agent_with_mcp_client go run ./agent_with_mcp_client "List tools you can call." ``` -------------------------------- ### Run full example suite Source: https://github.com/agenticenv/agent-sdk-go/blob/main/CONTRIBUTING.md Runs the full example suite; requires Task, Docker, and LLM credentials. ```bash task examples:all ``` -------------------------------- ### Run the local durable agent Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/durable-agent-local.mdx Run the example from the `examples/` directory after configuration. No runtime environment variables or server setup are needed. ```bash go run ./durable_agent/local ``` -------------------------------- ### pgvector setup commands Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/retrieval.mdx Start the pgvector infrastructure, run the pgvector agent with a sample question, and then tear down the infrastructure. The question should be concrete and aligned with the sample KB (e.g., return policy). ```bash task infra:pgvector:up ``` ```bash go run ./agent_with_retriever/pgvector "What is the return policy?" ``` ```bash task infra:pgvector:down ``` -------------------------------- ### Run the Stream Conversation Example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/stream-conversation.mdx Run commands from the examples/ directory. The first starts the example; the second passes a prompt. Tokens print as they stream, and the run exits after RUN_FINISHED. ```bash go run ./agent_with_stream_conversation go run ./agent_with_stream_conversation "What is 5 * 8?" ``` -------------------------------- ### Run the agent with conversation example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/conversation.mdx Starts the Redis infrastructure and runs the agent example in interactive mode or with a single-turn prompt. Interactive mode accepts multiple prompts until you type 'exit'. ```bash task infra:redis:up go run ./agent_with_conversation go run ./agent_with_conversation "Hello, remember I'm Alice" ``` -------------------------------- ### Run AG-UI / CopilotKit example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs the AG-UI / CopilotKit example. Requires two processes: the Go SSE server on :8787 and the Next.js UI. See agent_with_agui/README.md for curl testing and UI setup. ```bash # Terminal 1: Go agent server (listens on :8787) go run ./agent_with_agui/server # Terminal 2: Next.js UI cd agent_with_agui/ui && npm install && npm run dev ``` -------------------------------- ### Run the A2A client example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/a2a-client.mdx Run the example from the examples/ directory. The second command passes a query to the agent. ```bash go run ./agent_with_a2a_client ``` ```bash go run ./agent_with_a2a_client "What tools do you have available?" ``` -------------------------------- ### Install agent-sdk-go with go get Source: https://github.com/agenticenv/agent-sdk-go/blob/main/README.md Use this command to install the latest version of the agent-sdk-go module. Requires Go 1.26 or later. ```bash go get github.com/agenticenv/agent-sdk-go@latest ``` -------------------------------- ### Run the A2A config example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/a2a-config.mdx Run the example from the examples/ directory. The first command runs the example with default settings, the second passes a prompt to ask about available tools. ```bash go run ./agent_with_a2a_config ``` ```bash go run ./agent_with_a2a_config "What tools do you have available?" ``` -------------------------------- ### Run the hooks example (default demo) Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/hooks.mdx Runs the example from the examples/ directory. This is the default two-run demo that stores memories, prefetches retrieval, and uses tools, then recalls. ```bash go run ./agent_with_hooks ``` -------------------------------- ### Run agent_with_budget example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/agent-with-budget.mdx Run the example from the examples/ directory. Two commands are shown: one without arguments and one with a prompt string. The limits are intentionally low to trigger on a short prompt; raise them for real workloads. ```bash go run ./agent_with_budget ``` ```bash go run ./agent_with_budget "Tell me a short interesting fact about space." ``` -------------------------------- ### Run agent examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_observability/README.md Run the agent examples with default configuration. The first command uses WithObservabilityConfig, the second uses WithTracer / WithMetrics / WithLogs. ```bash go run ./examples/agent_with_observability/config/ ``` ```bash go run ./examples/agent_with_observability/objects/ ``` -------------------------------- ### Start local Restate server with restate-server Source: https://github.com/agenticenv/agent-sdk-go/blob/main/restate-setup.md Starts a local Restate server using the restate-server binary. Install it first via Restate's official instructions; for local admin registration, Restate docs often recommend RESTATE_ADVERTISED_HOST=127.0.0.1 restate-server. Use restate-server --help for more options. ```bash restate-server ``` -------------------------------- ### Run Temporal workflow example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/workflows.mdx Starts Temporal infrastructure and runs the agent with the Temporal runner for durable execution. Requires `LLM_APIKEY` in `examples/.env`. ```bash task infra:temporal:up && task infra:temporal:wait ORCHESTRATION_ENGINE=temporal go run ./agent_with_workflows "Run the onboarding workflow for user Alice" ``` -------------------------------- ### Run the agent_with_subagents example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/subagents.mdx Run the example from the examples/ directory. Approve delegation and tool calls when prompted on stdin. ```bash go run ./agent_with_subagents "Use the math specialist to compute 847 * 293" ``` -------------------------------- ### Run concurrent agent example with AGENT_RUNTIME Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/concurrent-runs.mdx Commands to run the example with the local (default), Temporal, or Restate runtime. Set AGENT_RUNTIME to switch runtimes; Temporal and Restate require starting their infrastructure first. ```bash # local runtime (default) go run ./agent_with_concurrent_runs # pass your own prompts go run ./agent_with_concurrent_runs "Who wrote Hamlet?" "What is sqrt(144)?" "Name a primary color." # Temporal task infra:temporal:up && task infra:temporal:wait AGENT_RUNTIME=temporal go run ./agent_with_concurrent_runs # Restate task infra:restate:up && task infra:restate:wait AGENT_RUNTIME=restate go run ./agent_with_concurrent_runs ``` -------------------------------- ### Run all agent_with_tools examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/tools.mdx Run each example from the examples/ directory. Each command executes a different tool configuration: basic (built-in tools with auto-approval), approval (prompts for each tool call), authorizer (programmatic deny), custom (custom Reverse tool), and dynamic_registry (tool added between runs). ```bash go run ./agent_with_tools/basic "What's the weather in Tokyo?" go run ./agent_with_tools/approval "What is 15 + 27?" go run ./agent_with_tools/authorizer "Get the protected note for roadmap." go run ./agent_with_tools/custom "Reverse 'hello world'" go run ./agent_with_tools/dynamic_registry ``` -------------------------------- ### Create and run an in-process agent with NewAgent Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/runtimes/in-process.mdx Create an agent with the in-process runtime by omitting Temporal and Restate options. The agent loop runs in-process and is durable by default via durable-go. The example shows error handling for agent creation and run start, and retrieving the result with Get. ```go a, err := agent.NewAgent( agent.WithLLMClient(llmClient), agent.WithSystemPrompt("You are a helpful assistant."), ) if err != nil { return err } defer a.Close() agentRun, err := a.Run(ctx, "Hello", nil) if err != nil { // handle start error } result, err := agentRun.Get(ctx) ``` -------------------------------- ### Run the agent_with_stream example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/stream.mdx Run the example from the examples/ directory with a prompt argument. Two sample prompts are provided: one for weather and one for arithmetic. ```bash go run ./agent_with_stream "What's the weather in Tokyo?" go run ./agent_with_stream "What is 15 + 27?" ``` -------------------------------- ### Setup pgvector infrastructure Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_memory/README.md Starts and stops the pgvector Docker infrastructure using Task. Run 'task infra:pgvector:up' to start, and 'task infra:pgvector:down' when finished. ```bash cd examples task infra:pgvector:up task infra:pgvector:down # when finished ``` -------------------------------- ### Run Simple Agent example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/quickstart.mdx Run the Simple Agent example from the repository root. Requires setting LLM_APIKEY, LLM_PROVIDER, and LLM_MODEL environment variables; see Running Examples for details. ```bash export LLM_APIKEY=your-key export LLM_PROVIDER=openai export LLM_MODEL=gpt-4o go run ./examples/simple_agent "Hello" ``` -------------------------------- ### Run single example with go run Source: https://github.com/agenticenv/agent-sdk-go/blob/main/CONTRIBUTING.md Runs a single example, simple_agent, with the argument "Hello". ```bash go run ./examples/simple_agent "Hello" ``` -------------------------------- ### Run MCP config example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/mcp-config.mdx Run the example from the examples/ directory. The first command runs without a prompt, the second passes a prompt to list available tools. ```bash go run ./agent_with_mcp_config go run ./agent_with_mcp_config "List tools you can call." ``` -------------------------------- ### Run reconnect example with Temporal or Restate Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/reconnect.mdx Commands to start the required durable runtime (Temporal or Restate) and run the reconnect example. The same public API works on both runtimes; the local runtime has no stream offsets. ```bash # Temporal task infra:temporal:up && task infra:temporal:wait AGENT_RUNTIME=temporal go run ./agent_with_reconnect "What time is it?" # Restate task infra:restate:up && task infra:restate:wait AGENT_RUNTIME=restate go run ./agent_with_reconnect "What time is it?" ``` -------------------------------- ### Run the agent_with_reasoning example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/reasoning.mdx Run the example from the examples/ directory. The first command runs with default settings; the second passes a prompt as an argument. Use a model that supports extended thinking for your provider, such as claude-sonnet-4-20250514 with Anthropic or o3 with OpenAI. ```bash go run ./agent_with_reasoning ``` ```bash go run ./agent_with_reasoning "Why is the sky blue? One short paragraph." ``` -------------------------------- ### Run MCP config and client examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs the MCP examples using the same MCP_* environment variables from .env.defaults. The agent_with_mcp_config example uses WithMCPConfig, while agent_with_mcp_client uses mcpclient.NewClient and WithMCPClients. The commands with a message ask the agent to list available tools. ```bash go run ./agent_with_mcp_config ``` ```bash go run ./agent_with_mcp_config "List tools you can call." ``` ```bash go run ./agent_with_mcp_client ``` ```bash go run ./agent_with_mcp_client "List tools you can call." ``` -------------------------------- ### Run error handling with a.Run and run.Get Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/runtimes/in-process.mdx Shows how to start a run and retrieve its result on the in-process runtime. Errors are returned directly to the caller: the first error is a start error (e.g., context cancelled or config issue), and the second is a run error (e.g., LLM failure, tool panic, timeout, or context cancelled). If the start error is nil, the run started and you check the result via Get. ```go run, err := a.Run(ctx, prompt, nil) if err != nil { // Start error (context cancelled, config issue) // If nil, the run started; check result via Get } result, err := run.Get(ctx) if err != nil { // Run error (LLM failure, tool panic, timeout, context cancelled) // result may be nil or partially populated } ``` -------------------------------- ### Install and run the Next.js UI Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_agui/README.md Installs dependencies and starts the Next.js UI development server. The dev server runs the Copilot runtime at /api/copilotkit, which forwards requests to the Go server at http://127.0.0.1:8787/agui by default. Open http://localhost:3000 to use the chat UI. ```bash cd examples/agent_with_agui/ui npm install npm run dev ``` -------------------------------- ### Quick start with environment variables Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/cli.mdx Sets required environment variables and runs a one-shot prompt or starts an interactive chat. ```bash export AGCTL_LLM_APIKEY=sk-your-key export AGCTL_LLM_PROVIDER=openai export AGCTL_LLM_MODEL=gpt-4o agctl run --prompt "Hello" agctl chat ``` -------------------------------- ### Run agent examples with go run Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_mcp_config/README.md Run the agent examples from the examples/ directory. The optional quoted argument is a prompt for the agent. ```bash go run ./agent_with_mcp_config go run ./agent_with_mcp_config "List tools you can call." go run ./agent_with_mcp_client go run ./agent_with_mcp_client "List tools you can call." ``` -------------------------------- ### Run multiple agents with Temporal Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/multiple-agents.mdx Starts Temporal infrastructure and runs the multiple agents example with the Temporal runtime. Requires the task CLI and Temporal services. ```bash task infra:temporal:up && task infra:temporal:wait AGENT_RUNTIME=temporal go run ./multiple_agents ``` -------------------------------- ### Build agent examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_observability/README.md Build the agent examples for verification only, without running them. ```bash go build -o /dev/null ./examples/agent_with_observability/config/ ``` ```bash go build -o /dev/null ./examples/agent_with_observability/objects/ ``` -------------------------------- ### Run the non-blocking agent example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/nonblocking-run.mdx Run the example from the examples/ directory. When the calculator tool is invoked, type y or n at the approval prompt. If you wait ~10s without answering, the example calls Cancel. ```bash go run ./agent_with_nonblocking_run "What is 15 + 27?" ``` -------------------------------- ### Run the JSON response example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/json-response.mdx Run the example from the examples/ directory. The agent will respond with structured JSON matching the configured schema. ```bash go run ./agent_with_json_response "What is the capital of France?" ``` -------------------------------- ### Run non-blocking, concurrent, and multiple agents examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs examples for non-blocking Run, concurrent runs, and multiple agents. The commands demonstrate starting runs without blocking, running multiple concurrent runs, and using multiple agents with optional concurrent mode. ```bash go run ./agent_with_nonblocking_run "What is 15 + 27?" ``` ```bash go run ./agent_with_concurrent_runs ``` ```bash go run ./agent_with_concurrent_runs "Who wrote Hamlet?" "What is sqrt(144)?" "Name a primary color." ``` ```bash go run ./multiple_agents "What is 7 times 8?" ``` ```bash go run ./multiple_agents concurrent "What is 7 times 8?" ``` -------------------------------- ### Run durable agent with Temporal Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Run the durable agent example for Temporal. The first command starts the worker in terminal 1, and the second starts the agent in terminal 2. Requires AGENT_RUNTIME=temporal and a running Temporal server. ```bash AGENT_RUNTIME=temporal go run ./durable_agent/temporal/worker # terminal 1 AGENT_RUNTIME=temporal go run ./durable_agent/temporal/agent "Hello from remote agent!" # terminal 2 ``` -------------------------------- ### Partial config file example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/cli.mdx Example partial configuration file showing only the keys to change; unspecified keys retain defaults. ```yaml # ~/my-agctl.yaml llm: model: gpt-4o-mini tools: weather: enabled: false ``` -------------------------------- ### Run observability examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/observability.mdx Runs the two observability examples from the examples directory. Call Agent.Close() before exit so OTLP batches flush. ```bash go run ./agent_with_observability/config/ go run ./agent_with_observability/objects/ ``` -------------------------------- ### Run agent_with_error_control example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/error-control.mdx Run the example from the examples/ directory. The sample uses stub LLM clients and a stub tool, so no provider key is needed. Set AGENT_RUNTIME=temporal or restate in examples/.env to exercise those runtimes. ```bash go run ./agent_with_error_control ``` -------------------------------- ### Run example with logging controls Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/logs.mdx Run the simple_agent example from the examples/ directory. The first command uses default settings (no SDK logs). The second enables debug logging. The third enables info logging and redirects stderr to debug.log. ```bash go run ./simple_agent "Hello" # default: no SDK logs LOG_ENABLE=true LOG_LEVEL=debug go run ./simple_agent "Hello" # enable for debugging LOG_ENABLE=true LOG_LEVEL=info go run ./simple_agent "Hello" 2>debug.log ``` -------------------------------- ### Expected output for all agent_with_tools examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/tools.mdx Expected output for each example. The basic example prints the answer directly, approval prompts for each tool call, authorizer denies access, custom reverses the input, and dynamic_registry shows no tools on the first run and the tool on the second. ```text # basic — auto-approval, answer printed directly The current weather in Tokyo is 18°C, partly cloudy with light winds. # approval — prompt appears for each tool call Tool call: calculator({"expression":"15+27"}) Approve? [y/n]: y 15 + 27 = 42 # authorizer — programmatic deny Access denied: you do not have permission to access the protected note. # custom — custom Reverse tool "hello world" reversed is "dlrow olleh" # dynamic_registry — tool added between runs [Run 1] No tools available. [Run 2] reversed: "dlrow olleh" ``` -------------------------------- ### Create agent and run with Run() Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/simple-agent.mdx Key code from the simple agent example: creates an agent with a name, system prompt, and LLM client, then runs it once and prints the result content. The commented line notes that config.RuntimeOption(cfg) adds Temporal or Restate options when AGENT_RUNTIME is set. The example loads LLM settings from examples/.env. ```go a, err := agent.NewAgent( agent.WithName("simple-agent"), agent.WithSystemPrompt("You are a helpful assistant that can generate text."), agent.WithLLMClient(llmClient), // config.RuntimeOption(cfg) adds Temporal or Restate options when AGENT_RUNTIME is set ) if err != nil { log.Fatal(err) } defer a.Close() agentRun, err := a.Run(ctx, prompt, nil) if err != nil { log.Fatal(err) } result, err := agentRun.Get(ctx) if err != nil { log.Fatal(err) } fmt.Println(result.Content) ``` -------------------------------- ### Run agent examples with prompt Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_observability/README.md Run the agent examples with an optional prompt as an extra argument. If no prompt is provided, a default prompt is used. ```bash go run ./examples/agent_with_observability/config/ "Say hello in one sentence" ``` ```bash go run ./examples/agent_with_observability/objects/ "Say hello in one sentence" ``` -------------------------------- ### Run multiple agents with Restate Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/multiple-agents.mdx Starts Restate infrastructure and runs the multiple agents example with the Restate runtime. Requires the task CLI and Restate services. ```bash task infra:restate:up && task infra:restate:wait AGENT_RUNTIME=restate go run ./multiple_agents ``` -------------------------------- ### Run durable agent with Restate Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Run the durable agent example for Restate. First starts the Restate infrastructure and waits for it, then runs the agent with AGENT_RUNTIME=restate. ```bash task infra:restate:up && task infra:restate:wait AGENT_RUNTIME=restate go run ./durable_agent/restate "Hello from Restate durable agent!" ``` -------------------------------- ### Run A2A examples from examples/ directory Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_a2a_config/README.md Commands to run the two A2A examples. The optional argument is a prompt to send to the agent. ```bash go run ./agent_with_a2a_config go run ./agent_with_a2a_config "What tools do you have available?" go run ./agent_with_a2a_client go run ./agent_with_a2a_client "What tools do you have available?" ``` -------------------------------- ### Run memory examples with or without CLI args Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/memory.mdx Run the memory examples with no CLI args for a two-run demo, or with a custom prompt as a single run. ```bash go run ./agent_with_memory/weaviate go run ./agent_with_memory/pgvector "Remember I prefer window seats." ``` -------------------------------- ### Wait for the result with Agent.Run and Get Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/run.mdx Use Agent.Run to start an agent and immediately call Get on the returned AgentRun to block until the result is available. The example shows error handling and printing the result content. ```go agentRun, err := a.Run(ctx, "Hello! What can you help me with?", nil) if err != nil { return err } result, err := agentRun.Get(ctx) if err != nil { return err } fmt.Println(result.Content) ``` -------------------------------- ### Install agctl with go install Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/cli.mdx Installs agctl using Go 1.26+; the binary is placed in $(go env GOPATH)/bin. ```bash go install github.com/agenticenv/agent-sdk-go/cli@latest ``` -------------------------------- ### Run agent with workflows (in-process and Temporal) Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs the agent with workflows example. The first command uses the in-process runner (no infra). The second uses Temporal for durable execution, requiring infra setup and the ORCHESTRATION_ENGINE=temporal environment variable. ```bash # in-process runner (default — no infrastructure needed) go run ./agent_with_workflows "Run the onboarding workflow for user Alice" # Temporal runner — durable execution task infra:temporal:up && task infra:temporal:wait ORCHESTRATION_ENGINE=temporal go run ./agent_with_workflows "Run the onboarding workflow for user Alice" ``` -------------------------------- ### Run MCP config example with streamable HTTP server Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/mcp-config.mdx Run the example against a real HTTP MCP server. The .env file must be configured with MCP_TRANSPORT=streamable_http and MCP_STREAMABLE_HTTP_URL pointing to your server. ```bash # In examples/.env: # MCP_TRANSPORT=streamable_http # MCP_STREAMABLE_HTTP_URL=http://localhost:8123/mcp go run ./agent_with_mcp_config ``` -------------------------------- ### Run the durable engine example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/durable-engine.mdx Runs the durable engine example from the examples/ directory. Local runtime only; no Temporal or Restate required. ```bash go run ./agent_with_durable_engine "Hello, what can you do?" ``` -------------------------------- ### Run the pgvector example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_memory/README.md Runs the pgvector example with optional query argument. The second command includes a sample query. ```bash go run ./agent_with_memory/pgvector go run ./agent_with_memory/pgvector "What answer style do I prefer?" ``` -------------------------------- ### Run caller-owned Temporal client example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Run the example that creates and manages a Temporal client directly, useful for TLS, Temporal Cloud API keys, or custom connection options. Requires AGENT_RUNTIME=temporal and a running Temporal server. ```bash AGENT_RUNTIME=temporal go run ./agent_with_temporal_client "Hello, what can you do?" ``` -------------------------------- ### Expected output from MCP client example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/mcp-client.mdx The expected output when running the example, indicating the agent has access to the read_file and list_directory tools. ```text I have access to read_file and list_directory tools from the configured MCP server. What would you like to do? ``` -------------------------------- ### Start Restate server Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/durable_agent/restate/README.md Starts the Restate server and waits for it to be ready. Run from the examples/ directory. Stop with `task infra:restate:down` when finished. ```bash task infra:restate:up && task infra:restate:wait ``` -------------------------------- ### Temporal runtime configuration and run/stream example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/README.md Configures the agent to use the Temporal runtime for distributed execution, then runs and streams a response. The example shows how to set the Temporal host, port, namespace, and task queue, and how to reconnect to a stream using a saved run ID and offset. Mutually exclusive with Restate. ```go import "github.com/agenticenv/agent-sdk-go/pkg/agent/runtime/temporal" a, _ := agent.NewAgent( agent.WithSystemPrompt("You are a helpful assistant."), agent.WithLLMClient(llmClient), temporal.WithTemporalConfig(&temporal.TemporalConfig{ Host: "localhost", Port: 7233, Namespace: "default", TaskQueue: "agent-task-queue", }), ) defer a.Close() // --- Run --- run, _ := a.Run(context.Background(), "Reply with a short greeting.", nil) result, _ := run.Get(context.Background()) fmt.Println(result.Content) // --- Stream + reconnect --- stream, _ := a.Stream(context.Background(), "Write a four-line poem about the ocean.", nil) savedRunID := stream.ID() // persist before consuming events events, _ := stream.Events(context.Background()) for event := range events { // persist event.Offset() before handling — needed for WithOffset on reconnect _ = event } savedOffset := int64(0) s, _ := a.GetAgentStream(context.Background(), savedRunID) ch, _ := s.Events(context.Background(), agent.WithOffset(savedOffset)) for event := range ch { _ = event } ``` -------------------------------- ### Expected output for the sub-agent example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/subagents.mdx Expected output when running the example. Shows the delegation approval prompt, tool call approval, and the computed result. ```text Delegating to math-specialist... Approve delegation to math-specialist? [y/n]: y Tool call: calculator({"expression":"847*293"}) Approve? [y/n]: y 847 × 293 = 248,171 ``` -------------------------------- ### Expected startup output Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/durable_agent/restate/README.md Expected output when starting the agent. Shows the banner and the `you>` prompt. ```text === durable_agent/restate interactive stream === Events are durable via Restate (embedded SDK endpoint). Kill this process mid-stream (Ctrl+C / pkill), keep Restate up, then restart to reconnect. Type 'exit' or 'quit' or 'bye' to stop. you> ``` -------------------------------- ### Install and use the a2a CLI Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/a2a-server.mdx Installs the a2a CLI and demonstrates discover and send commands against the local server. With bearer tokens configured, see 'a2a help send' for auth flags. ```bash go install github.com/a2aproject/a2a-go/v2/cmd/a2a@latest a2a discover http://localhost:9999 a2a send http://localhost:9999 "Hello, what can you do?" ``` -------------------------------- ### Run A2A config and client examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs the A2A client examples for outbound A2A tools. Requires setting A2A_URL and optional A2A_* variables in .env.defaults. The commands with a message ask the agent to list available tools. ```bash go run ./agent_with_a2a_config ``` ```bash go run ./agent_with_a2a_config "What tools do you have available?" ``` ```bash go run ./agent_with_a2a_client ``` ```bash go run ./agent_with_a2a_client "What tools do you have available?" ``` -------------------------------- ### Run agent with MCP config Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_mcp_config/README.md Run the agent example after configuring MCP_TRANSPORT and MCP_STREAMABLE_HTTP_URL in examples/.env. ```bash go run ./agent_with_mcp_config ``` -------------------------------- ### Check infrastructure status Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/memory.mdx Check the status of the Docker infrastructure before starting the memory examples. ```bash task infra:status # see what's running ``` -------------------------------- ### Expected output from multiple agents example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/multiple-agents.mdx Expected console output when running the example, showing each agent's greeting message. ```text --- Agent 1 (math) --- Agent 1 (math): Hello from the math assistant! I'm ready to help. --- Agent 2 (creative) --- Agent 2 (creative): Hello from the creative writing assistant! ``` -------------------------------- ### Sample prompt input Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/durable_agent/restate/README.md Example prompt to type at the `you>` prompt. ```text Hello from Restate durable agent! ``` -------------------------------- ### Run the hooks example with a PII-triggering prompt Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/hooks.mdx Runs the example with a prompt containing an email address, which triggers PII redaction. Watch stderr for [hooks] lines as each hook fires. ```bash go run ./agent_with_hooks "My email is alice@example.com. What is the return policy?" ``` -------------------------------- ### Quick start: run worker and agent Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/durable_agent/temporal/README.md Quick start commands to run the worker and agent from the examples/ directory. Run the worker in terminal 1 and the agent in terminal 2. The agent command is one-shot; for interactive REPL and durability scenarios, see the scenarios below. ```bash go run ./durable_agent/temporal/worker ``` ```bash go run ./durable_agent/temporal/agent "Hello from remote agent!" ``` -------------------------------- ### Run minimal agent Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs the minimal agent example with no tools. Pass a prompt as the argument. ```bash go run ./simple_agent "Hello, what can you do?" ``` -------------------------------- ### Create a Go module and install agent-sdk-go Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/quickstart.mdx Initializes a new Go module and fetches the agent-sdk-go package. Run these commands in a terminal before writing the agent code. ```bash mkdir my-agent && cd my-agent go mod init example.com/my-agent go get github.com/agenticenv/agent-sdk-go@latest ``` -------------------------------- ### Run streaming agent Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs the streaming example, showing partial content as tokens arrive. ```bash go run ./agent_with_stream "What's the current time and what's 17 * 23?" ``` -------------------------------- ### Start durable runtime and set AGENT_RUNTIME Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_reconnect/README.md Start the durable runtime (Temporal or Restate) and set the AGENT_RUNTIME environment variable. Run these commands from the examples/ directory. ```bash task infra:temporal:up && task infra:temporal:wait AGENT_RUNTIME=temporal ``` ```bash task infra:restate:up && task infra:restate:wait AGENT_RUNTIME=restate ``` -------------------------------- ### Check infra status Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/retrieval.mdx Run from the examples/ directory to check the status of the infrastructure before starting the retrieval examples. ```bash task infra:status ``` -------------------------------- ### Create and start an agent worker with NewAgentWorker Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/advanced/distributed-execution.mdx Sets up a worker process that polls the task queue and executes runs. Uses the Temporal runtime with a specified host, port, namespace, and task queue. Starts the worker in a goroutine and includes a comment for graceful shutdown with w.Stop(). ```go w, err := agent.NewAgentWorker( temporal.WithTemporalConfig(&temporal.TemporalConfig{ Host: "localhost", Port: 7233, Namespace: "default", TaskQueue: "my-app", }), agent.WithLLMClient(llmClient), agent.WithSystemPrompt("You are a helpful assistant."), ) if err != nil { log.Fatal(err) } go func() { if err := w.Start(ctx); err != nil { log.Fatal(err) } }() // On shutdown: // w.Stop() ``` -------------------------------- ### Expected output from code execution example Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/code-execution.mdx Expected output from the example: the user prompt and the agent's response with the first 10 Fibonacci numbers. ```text user: Write a Python script that prints the first 10 Fibonacci numbers A: Here are the first 10 Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. ``` -------------------------------- ### Non-blocking Run with Done, Status, Cancel, and Get Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/run.mdx Shows a non-blocking pattern: start a run, persist the ID, then loop on Done and a timer to poll Status. After two polls, it cancels the run, after which Done closes and Get returns. Cancelling the Get context only unblocks the waiter; use AgentRun.Cancel to cancel the run. ```go agentRun, err := a.Run(ctx, "Summarize this document", nil) if err != nil { return err } _ = agentRun.ID() // persist before waiting when crash-durability matters polls := 0 for { select { case <-agentRun.Done(): result, err := agentRun.Get(ctx) if err != nil { return err } fmt.Println(result.Content) return nil case <-time.After(5 * time.Second): polls++ st, _ := agentRun.Status(ctx) fmt.Println("still running, status:", st) if polls >= 2 { _ = agentRun.Cancel(ctx) // then Done closes and Get returns } } } ``` -------------------------------- ### Example config.yaml for agctl Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/cli.mdx Example configuration file for agctl. Shows how to set runtime, agent name, system prompt, LLM provider settings, conversation store, logger, and tool toggles. Includes commented-out sections for temporal, restate, and MCP servers. ```yaml runtime: local name: agctl system_prompt: "You are a helpful agent. Use available tools when they improve accuracy." llm: provider: openai apiKey: "" # prefer AGCTL_LLM_APIKEY model: gpt-4o baseURL: https://api.openai.com/v1 conversation: store: inmem max_size: 100 size: 20 save_on_iteration: true logger: level: info output: logs/agctl.log format: json llm_usage: false tools: echo: { enabled: true } calculator: { enabled: true } weather: { enabled: false } # Uncomment when using temporal: # temporal: # host: localhost # port: 7233 # namespace: default # taskQueue: agent-sdk-go # Uncomment when using restate: # restate: # ingressURL: http://localhost:8080 # adminURL: http://localhost:9070 # endpointListenAddress: ":9080" # Optional MCP — see section below # mcp: # servers: [...] ``` -------------------------------- ### Run vector retriever examples Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/README.md Runs the vector retriever examples. Requires a running vector store: Weaviate or Postgres with pgvector, with backend-specific variables set in .env.defaults. The first two commands use Weaviate and pgvector respectively, and the third uses RETRIEVER_MODE=prefetch with Weaviate. ```bash # Weaviate (task infra:weaviate:up first; task infra:weaviate:down when done) go run ./agent_with_retriever/weaviate "What is the return policy?" ``` ```bash # pgvector (task infra:pgvector:up first; task infra:pgvector:down when done) go run ./agent_with_retriever/pgvector "What is the return policy?" ``` ```bash RETRIEVER_MODE=prefetch go run ./agent_with_retriever/weaviate "What are the return and shipping rules?" ``` -------------------------------- ### Start Temporal with task infra:temporal:up Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/durable-agent.mdx Starts the local Temporal dev server and waits until it is ready. With the local Docker dev server, open http://localhost:8233 (Temporal Web UI) to inspect workflows and activities in namespace default. ```bash task infra:temporal:up && task infra:temporal:wait ``` -------------------------------- ### Start agent and send long prompt (scenario 3) Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/durable_agent/restate/README.md Starts the agent and sends a long prompt for the graceful shutdown scenario. Wait until streaming tokens appear before pressing Ctrl+C. ```bash go run ./durable_agent/restate ``` ```text you> Write a detailed essay about durable execution and why crash recovery matters. ``` ```text [run_id] --- stream start --- Durable execution means... ``` -------------------------------- ### Start with explicit deployment URL (Docker networking) Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/durable_agent/restate/README.md Starts the agent with an explicit deployment URL for Docker networking. This is the fix for registration failures when Restate runs in Docker and the agent runs on the host. ```bash RESTATE_DEPLOYMENT_URL=http://host.docker.internal:9080 go run ./durable_agent/restate ``` -------------------------------- ### Run agent_with_a2a_config against local server Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_a2a_config/README.md Command to run the agent_with_a2a_config example after setting A2A_URL in examples/.env. ```bash go run ./agent_with_a2a_config ``` -------------------------------- ### Restate runtime chat Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/cli.mdx Starts a chat with the Restate runtime, with optional deployment URL override. See restate-setup.md for local server setup. ```bash agctl chat --runtime restate # optional overrides (defaults: ingress http://localhost:8080, admin http://localhost:9070, listen :9080) agctl chat --runtime restate --restate-deployment-url http://host.docker.internal:9080 ``` -------------------------------- ### Expected stdout (assistant reply) Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/hooks.mdx Expected stdout (assistant reply) when running the example with the default prompt. ```text Our return policy allows returns within 30 days. I've noted your query. ``` -------------------------------- ### Create examples/.env with LLM credentials Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/configuration.mdx Appends the required environment variables to examples/.env. The file is gitignored and should only contain your API key and overrides; .env.defaults is loaded automatically and should not be copied. Load order is .env.defaults, then .env, then process environment, with process-level exports taking precedence. ```bash cd examples cat >> .env <<'EOF' LLM_APIKEY=your-key-here LLM_PROVIDER=openai LLM_MODEL=gpt-4o EOF ``` -------------------------------- ### Stream agent events with Agent.Stream in Go Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/streaming.mdx Use Agent.Stream to get an AgentStream handle, then consume events from the Events channel. Cancelling streamCtx cancels the agent run; use a separate eventsCtx to drop the subscriber without stopping the run. The example shows checking status, iterating events, and waiting for completion with Done and Get. ```go // Cancelling streamCtx cancels the agent run. Use a separate eventsCtx if you need // to drop the subscriber without stopping the run (reconnect / crash simulation). streamCtx := ctx agentStream, err := a.Stream(streamCtx, prompt, nil) if err != nil { return err } _ = agentStream.ID() st, _ := agentStream.Status(ctx) fmt.Println("status:", st) eventCh, err := agentStream.Events(ctx) if err != nil { return err } for ev := range eventCh { // handle events } // Optional: wait for completion / read result after the channel closes <-agentStream.Done() result, err := agentStream.Get(ctx) ``` -------------------------------- ### Run Jaeger all-in-one container for local OTLP Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/observability/tracing.mdx Starts a local Jaeger instance with the OpenTelemetry Collector-compatible ports (4317 for gRPC, 16686 for UI). Required for local OTLP tracing setup. ```bash docker run --rm -p 4317:4317 -p 16686:16686 jaegertracing/all-in-one:latest ``` -------------------------------- ### Run simple agent with go run Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/simple-agent.mdx Run the simple agent example from the examples/ directory. The first command runs with a default prompt; the second enables the optional token usage footer by setting SHOW_LLM_USAGE=true. ```bash go run ./simple_agent "Hello, what can you do?" SHOW_LLM_USAGE=true go run ./simple_agent "Hello" ``` -------------------------------- ### Reconnect with GetAgentRun after crash Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/run.mdx On a durable runtime (Temporal or Restate), persist the run ID and use GetAgentRun to reconnect after a crash. Handles ErrRunAlreadyCompleted and ErrRunNotFound. Cancelling the GetAgentRun or Get context does not cancel the durable run; use AgentRun.Cancel. After reconnect, WithTimeout starts fresh. ```go run, err := a.GetAgentRun(ctx, savedRunID) if err != nil { if errors.Is(err, agent.ErrRunAlreadyCompleted) { // Run finished while disconnected — load outcome from // conversation/memory, or start a new run. return nil } return err // including ErrRunNotFound } result, err := run.Get(ctx) // or <-run.Done() then Get ``` -------------------------------- ### Run the execution config agent via go run Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/examples/execution-config.mdx Commands to run the example from the `examples/` directory. The optional argument demonstrates a custom query, and setting `AGENT_RUNTIME=temporal` runs the agent with the Temporal runtime. ```bash go run ./agent_with_execution_config ``` ```bash go run ./agent_with_execution_config "What is 99 times 77?" ``` ```bash AGENT_RUNTIME=temporal go run ./agent_with_execution_config ``` -------------------------------- ### Kill worker during LLM call (timeout) Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/durable_agent/temporal/README.md Simulates a worker crash during an LLM call with the worker left down. Start the worker and agent, send a longer prompt, then kill the worker with pkill -SIGKILL while streaming is active and do not restart it. The stream pauses with no immediate error; after the run timeout (3 minutes in this example) the error 'context deadline exceeded' surfaces, confirming the agent fails clearly on timeout rather than hanging indefinitely. Start the worker again to resume normal operation. ```bash go run ./durable_agent/temporal/worker ``` ```text Agent worker starting on task queue "agent-sdk-go-durable-agent_remote-worker". Run this before the agent. Agent worker running. Press Ctrl+C to stop (twice to force quit if shutdown hangs). ``` ```bash go run ./durable_agent/temporal/agent ``` ```text you> Write a detailed day-by-day travel plan for a 7-day trip to Japan. ``` ```bash pkill -SIGKILL -f 'go run ./durable_agent/temporal/worker|go-build/.*/worker' ``` ```text --- stream start --- ``` ```text [error] context deadline exceeded --- stream end --- you> ``` ```bash go run ./durable_agent/temporal/worker ``` -------------------------------- ### Run the Go agent server Source: https://github.com/agenticenv/agent-sdk-go/blob/main/examples/agent_with_agui/README.md Starts the Go agent server from the agent-sdk-go repo root. It listens on port 8787 by default; override with PORT= to avoid conflicts with apps on 8080. Health check is available at GET http://localhost:8787/health and the streaming endpoint is POST http://localhost:8787/agui. ```bash go run ./examples/agent_with_agui/server ``` -------------------------------- ### Verify agctl installation Source: https://github.com/agenticenv/agent-sdk-go/blob/main/docs/getting-started/cli.mdx Verifies the agctl installation by printing the version. ```bash agctl version ```