### Installation and Running the Example Source: https://docs.restate.dev/ai/patterns/parallelization Commands to install Restate, get the example, set the OpenAI API key, run the agent, register it with Restate, and start a request. ```bash restate-server ``` ```bash restate example python-langchain-tour-of-agents && cd python-langchain-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/parallel_tools_agent.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/ParallelToolClaimAgent/run --json '{ "date":"2024-10-01", "category":"orthopedic", "reason":"hospital bill for a broken leg", "amount":3000, "placeOfService":"General Hospital" }' ``` -------------------------------- ### Getting the Go Hello World Example Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Commands to download and navigate to the Go Hello World example project. ```bash restate example go-hello-world && cd go-hello-world ``` -------------------------------- ### Get the Greeter Service Template Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Clones the TypeScript Hello World example and installs its dependencies. ```bash restate example typescript-hello-world-bun && cd typescript-hello-world-bun && npm install ``` -------------------------------- ### TypeScript: Get and Run Example Source: https://docs.restate.dev/tour/workflows Steps to get the TypeScript workflow example, install dependencies, and run the development server. ```bash restate example typescript-tour-of-workflows && cd typescript-tour-of-workflows npm install npm run dev ``` -------------------------------- ### TypeScript: Get and Install Example Source: https://docs.restate.dev/tour/microservice-orchestration Commands to download, install dependencies for the TypeScript microservice orchestration example. ```bash restate example typescript-tour-of-orchestration && cd typescript-tour-of-orchestration npm install ``` -------------------------------- ### Bash Commands for Setting up and Running the TypeScript Example Source: https://docs.restate.dev/ai/patterns/sessions Commands to install Restate, get the example, install dependencies, set the API key, run the agent, and register services. ```bash restate-server ``` ```bash restate example typescript-restate-tour-of-agents && cd typescript-restate-tour-of-agents npm install ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash npx tsx ./src/chat-agent.ts ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` -------------------------------- ### Get the Greeter service template Source: https://docs.restate.dev/get_started/quickstart Download the Rust hello-world shuttle example. ```bash restate example rust-hello-world-shuttle && cd rust-hello-world-shuttle ``` -------------------------------- ### Installation and Running the Example Source: https://docs.restate.dev/ai/patterns/interrupt-regenerate Bash commands to install Restate, get the example, set up environment variables, and run the agent service. ```bash restate-server ``` ```bash restate example python-restate-agent-examples && cd python-restate-agent-agent-examples/interrupt-regenerate ``` ```bash echo 'OPENAI_API_KEY=sk-proj-...' > .env uv run --env-file .env . ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` -------------------------------- ### Bash: Install Restate and run example Source: https://docs.restate.dev/llms-full.txt Instructions for setting up the Restate server, installing the example project, and starting the agent service with an API key. ```bash restate-server ``` ```bash restate example typescript-restate-agent-examples && cd typescript-restate-agent-examples/interrupt-regenerate npm install ``` ```bash OPENAI_API_KEY=sk-proj-... npm run dev ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` -------------------------------- ### Bash Commands for Setting up and Running the Python Example Source: https://docs.restate.dev/ai/patterns/sessions Commands to install Restate, get the example, set the API key, run the agent, register services, and interact with the chat session. ```bash restate-server ``` ```bash restate example python-langchain-tour-of-agents && cd python-langchain-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/chat_agent.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/Chat/session123/message \ --json '{"message": "Make a poem about durable execution."}' ``` ```bash curl localhost:8080/Chat/session123/message \ --json '{"message": "Shorten it to 2 lines."}' ``` ```bash curl localhost:8080/Chat/session456/message \ --json '{"message": "What are the benefits of durable execution?"}' ``` -------------------------------- ### Installing and running the example Source: https://docs.restate.dev/llms-full.txt Commands to install Restate, get the Python LangChain example, and run it. ```bash restate-server ``` ```bash restate example python-langchain-tour-of-agents && cd python-langchain-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/remote_agents.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/MultiAgentClaimApproval/run --json '{ "date":"2024-10-01", "category":"orthopedic", "reason":"hospital bill for a broken leg", "amount":3000, "placeOfService":"General Hospital" }' ``` -------------------------------- ### Get the Greeter service template (Python) Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Command to download and navigate to the Python Greeter service example. ```bash restate example python-hello-world && cd python-hello-world ``` -------------------------------- ### Bash commands for setting up and running the Restate chat example Source: https://docs.restate.dev/ai/patterns/sessions Provides the necessary commands to install Restate, get the example code, set environment variables, and run the chat agent. ```bash restate-server ``` ```bash restate example python-restate-tour-of-agents && cd python-restate-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/chat_agent.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` -------------------------------- ### Running the multi-agent example Source: https://docs.restate.dev/ai/patterns/multi-agent Instructions to set up and run the multi-agent example, including installing Restate, getting the example code, setting the API key, and sending a request. ```bash restate-server ``` ```bash restate example typescript-restate-tour-of-agents && cd typescript-restate-tour-of-agents npm install ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash npx tsx ./src/multi-agent.ts ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/AgentRouter/answer \ --json '{"message": "I was charged twice for my subscription last month"}' ``` -------------------------------- ### Get the Greeter service template Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Downloads the Kotlin Hello World Gradle Spring Boot example and navigates into the project directory. ```bash restate example kotlin-hello-world-gradle-spring-boot && cd kotlin-hello-world-gradle-spring-boot ``` -------------------------------- ### Get the Greeter service template Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Clones the TypeScript Greeter service example and navigates into the project directory. ```bash restate example typescript-hello-world-deno && cd typescript-hello-world-deno ``` -------------------------------- ### Running the Google ADK Tour Example Source: https://docs.restate.dev/ai/patterns/human-in-the-loop This section provides the bash commands to set up and run the Google ADK tour example, including starting the Restate server, getting the example code, setting the Google API key, running the agent, and registering it with Restate. ```bash restate-server ``` ```bash restate example python-google-adk-tour-of-agents && cd python-google-adk-tour-of-agents ``` ```bash export GOOGLE_API_KEY=your-api-key ``` ```bash uv run app/human_approval_agent.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/HumanClaimApprovalAgent/user-123/run/send \ --json '{"message": "Process my hospital bill of 3000USD for a broken leg.", "session_id": "session-123"}' ``` ```bash curl localhost:8080/restate/awakeables/sign_1M28aqY6ZfuwBmRnmyP/resolve --json 'true' ``` -------------------------------- ### Restate Server Installation and Example Setup Source: https://docs.restate.dev/ai/patterns/human-in-the-loop These bash commands guide the user through installing Restate, getting the human approval agent example, setting up environment variables, running the agent, registering services, and simulating a claim approval. ```bash restate-server ``` ```bash restate example python-restate-tour-of-agents && cd python-restate-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/human_approval_agent.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/HumanClaimApprovalAgent/run/send \ --json '{"message": "Process my hospital bill of 3000USD for a broken leg."}' ``` ```bash curl localhost:8080/restate/awakeables/sign_1M28aqY6ZfuwBmRnmyP/resolve --json '"approved"' ``` -------------------------------- ### Running the Example Source: https://docs.restate.dev/ai/patterns/workflow-sequential Instructions and commands to set up and run the sequential workflow example. ```bash restate-server ``` ```bash restate example python-restate-tour-of-agents && cd python-restate-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/workflow_sequential.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/ClaimReimbursement/process --json '{ "message": "Process my hospital bill of 2024-10-01 for 3000USD for a broken leg at General Hospital." }' ``` -------------------------------- ### TypeScript Example Setup Source: https://docs.restate.dev/llms-full.txt Instructions to set up and run the TypeScript LLM example, including installing Restate, getting the example code, installing dependencies, setting the OpenAI API key, and running the application. ```bash restate-server ``` ```bash restate example typescript-restate-tour-of-agents && cd typescript-restate-tour-of-agents npm install ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash npx tsx ./src/workflow-evaluator-optimizer.ts ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/CodeGenerator/generate \ --json '{"task": "Write a function that checks if a string is a palindrome"}' ``` -------------------------------- ### Go: Get Example Source: https://docs.restate.dev/tour/microservice-orchestration Commands to download the Go microservice orchestration example. ```bash restate example go-tour-of-orchestration && cd go-tour-of-orchestration ``` -------------------------------- ### Clone and navigate to the example project Source: https://docs.restate.dev/quickstart Download and set up the Rust hello-world example project. ```shell restate example rust-hello-world && cd rust-hello-world ``` ```shell wget https://github.com/restatedev/examples/releases/latest/download/rust-hello-world.zip && unzip rust-hello-world.zip -d rust-hello-world && rm rust-hello-world.zip && cd rust-hello-world ``` -------------------------------- ### Go: Get and Run Example Source: https://docs.restate.dev/tour/workflows Steps to get the Go workflow example and run it. ```bash restate example go-tour-of-workflows && cd go-tour-of-workflows go run . ``` -------------------------------- ### Python Example Setup Source: https://docs.restate.dev/llms-full.txt Instructions to set up and run the Python LLM example, including installing Restate, getting the example code, setting the OpenAI API key, and running the application. ```bash restate-server ``` ```bash restate example python-langchain-tour-of-agents && cd python-langchain-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/workflow_evaluator_optimizer.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/CodeGenerator/generate \ --json '{"task": "Write a function that checks if a string is a palindrome"}' ``` -------------------------------- ### Java: Get Example Source: https://docs.restate.dev/tour/microservice-orchestration Commands to download the Java microservice orchestration example. ```bash restate example java-tour-of-orchestration && cd java-tour-of-orchestration ``` -------------------------------- ### Running the Example (Bash) Source: https://docs.restate.dev/ai/patterns/workflow-orchestrator These bash commands guide you through setting up and running the workflow orchestrator example, including installing Restate, getting the example code, setting up environment variables, and registering the agents. ```bash restate-server ``` ```bash restate example python-langchain-tour-of-agents && cd python-langchain-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/workflow_orchestrator.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/ResearchReport/generate \ --json '{"topic": "The impact of renewable energy on global economies"}' ``` -------------------------------- ### Java: Get and Run Example Source: https://docs.restate.dev/tour/workflows Steps to get the Java workflow example and run it using Gradle. ```bash restate example java-tour-of-workflows && cd java-tour-of-workflows ./gradlew run ``` -------------------------------- ### Get Example and Install Dependencies Source: https://docs.restate.dev/get_started/tour Commands to get the TypeScript tour example and install its npm dependencies. ```bash restate example typescript-tour-of-orchestration && cd typescript-tour-of-orchestration npm install ``` -------------------------------- ### Install and Run Restate Server Source: https://docs.restate.dev/ai/patterns/remote-agents These bash commands guide the user through installing Restate, getting the example code, setting up the Google API key, and running the multi-agent application. ```bash restate-server ``` ```bash restate example python-google-adk-tour-of-agents && cd python-google-adk-tour-of-agents ``` ```bash export GOOGLE_API_KEY=your-api-key ``` ```bash uv run app/remote_agents.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/MultiAgentClaimApproval/user123/run --json '{ "amount": 3000, "category": "orthopedic", "date": "2024-10-01", "placeOfService": "General Hospital", "reason": "hospital bill for a broken leg", "sessionId": "session-123" }' ``` -------------------------------- ### Python: Get Example Source: https://docs.restate.dev/tour/microservice-orchestration Commands to download the Python microservice orchestration example. ```bash restate example python-tour-of-orchestration && cd python-tour-of-orchestration ``` -------------------------------- ### TypeScript Chat Agent Example Setup Source: https://docs.restate.dev/llms-full.txt Steps to set up and run a TypeScript chat agent example using Restate, including installing dependencies, starting the server, and registering services. ```bash restate-server ``` ```bash restate example typescript-restate-tour-of-agents && cd typescript-restate-tour-of-agents npm install ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash npx tsx ./src/chat-agent.ts ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/Chat/session123/message \ --json '{"message": "make a poem about durable execution"}' ``` ```bash curl localhost:8080/Chat/session123/message \ --json '{"message": "shorten it to 2 lines"}' ``` -------------------------------- ### Python: Get and Run Example Source: https://docs.restate.dev/tour/workflows Steps to get the Python workflow example and run it. ```bash restate example python-tour-of-workflows && cd python-tour-of-workflows uv run . ``` -------------------------------- ### Get and Install TypeScript Example Source: https://docs.restate.dev/ai/patterns/workflow-parallel Downloads the TypeScript example and installs its dependencies. ```bash restate example typescript-restate-tour-of-agents && cd typescript-restate-tour-of-agents\nnpm install ``` -------------------------------- ### Bash Commands for Running the Example Source: https://docs.restate.dev/llms-full.txt These bash commands guide the user through installing Restate, getting the example code, setting up environment variables, running the application, registering services, and sending a test request. ```bash restate-server ``` ```bash restate example python-restate-tour-of-agents && cd python-restate-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/workflow_sequential.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/ClaimReimbursement/process --json '{ "message": "Process my hospital bill of 2024-10-01 for 3000USD for a broken leg at General Hospital." }' ``` -------------------------------- ### Bash commands for setting up and running the multi-agent example Source: https://docs.restate.dev/ai/patterns/multi-agent These bash commands guide you through installing Restate, getting the example code, setting your OpenAI API key, running the Python application, registering the agents with Restate, and sending a test claim request. ```bash restate-server ``` ```bash restate example python-openai-agents-tour-of-agents && cd python-openai-agents-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/multi_agent.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/MultiAgentClaimApproval/session123/run --json '{ "date":"2024-10-01", "category":"orthopedic", "reason":"hospital bill for a broken leg", "amount":3000, "placeOfService":"General Hospital" }' ``` -------------------------------- ### Bash commands for setting up and running the multi-agent example Source: https://docs.restate.dev/llms-full.txt These bash commands guide you through installing Restate, getting the Python multi-agent example, setting up your OpenAI API key, running the agent, registering it with Restate, and sending a test claim request. ```bash restate-server ``` ```bash restate example python-langchain-tour-of-agents && cd python-langchain-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/multi_agent.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/MultiAgentClaimApproval/session123/run --json '{ "date":"2024-10-01", "category":"orthopedic", "reason":"hospital bill for a broken leg", "amount":3000, "placeOfService":"General Hospital" }' ``` -------------------------------- ### Install Restate Server & CLI using npm Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Installs the Restate server and CLI globally using npm. ```bash npm install --global @restatedev/restate-server@latest @restatedev/restate@latest ``` -------------------------------- ### Download and install example service Source: https://docs.restate.dev/guides/connecting-k8s-services-to-cloud Downloads and installs the TypeScript Hello World service example. ```bash restate example typescript-hello-world && cd typescript-hello-world && npm install ``` -------------------------------- ### Run the Greeter service Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Starts the Greeter service development server. ```bash npm run dev ``` -------------------------------- ### Vercel AI Example: Installation and Running Source: https://docs.restate.dev/ai/patterns/multi-agent These bash commands guide the user through installing Restate, setting up the example project, and running the multi-agent system with an OpenAI API key. ```bash npm install --global @restatedev/restate-server@latest @restatedev/restate@latest restate-server ``` ```bash restate example typescript-vercel-ai-tour-of-agents && cd typescript-vercel-ai-tour-of-agents npm install ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash npx tsx ./src/multi-agent.ts ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/MultiAgentClaimApproval/run --json '{ "date":"2024-10-01", "category":"orthopedic", "reason":"hospital bill for a broken leg", "amount":3000, "placeOfService":"General Hospital" }' ``` -------------------------------- ### Get and Install TypeScript Example Source: https://docs.restate.dev/llms-full.txt Steps to download and set up the TypeScript racing agents example. ```bash restate example typescript-restate-tour-of-agents && cd typescript-restate-tour-of-agents npm install ``` -------------------------------- ### Run the Greeter service Source: https://docs.restate.dev/get_started/quickstart Starts the Greeter service development server using Quarkus. ```bash quarkus dev ``` -------------------------------- ### Run the Example Source: https://docs.restate.dev/get_started/tour Command to run the development server for the example. ```bash npm run dev ``` -------------------------------- ### Run this example (Bash) Source: https://docs.restate.dev/llms-full.txt Commands to install Restate, get the example, set the OpenAI API key, and run the Pydantic AI example. ```bash [Install Restate](/installation) and launch it: ```bash theme={null} restate-server ``` Get the example: ```bash theme={null} restate example python-pydantic-ai-tour-of-agents && cd python-pydantic-ai-tour-of-agents ``` Export your [OpenAI API key](https://platform.openai.com/api-keys) and run the agent: ```bash theme={null} export OPENAI_API_KEY=sk-... ``` ```bash theme={null} uv run app/workflow_orchestrator.py ``` Register the agents with Restate: ```bash theme={null} restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` Send a request: ```bash theme={null} curl localhost:8080/ResearchReport/generate \ --json '{"topic": "The impact of renewable energy on global economies"}' ``` ``` -------------------------------- ### Run SignupWithRetriesWorkflow Source: https://docs.restate.dev/tour/workflows Example of running the SignupWithRetriesWorkflow with different language clients. ```bash curl localhost:8080/SignupWithRetriesWorkflow/alice/run \ --json '{"name": "Alice", "email": "alice@mail.com"}' ``` ```bash curl localhost:8080/SignupWithRetriesWorkflow/alice/Run \ --json '{"name": "Alice", "email": "alice@mail.com"}' ``` ```bash curl localhost:8080/SignupWithRetriesWorkflow/alice/run \ --json '{"name": "Alice", "email": "alice@mail.com"}' ``` -------------------------------- ### Get the Greeter service template (wget) Source: https://docs.restate.dev/quickstart Alternatively, download the Kotlin Hello World Gradle example using wget. ```shell wget https://github.com/restatedev/examples/releases/latest/download/kotlin-hello-world-gradle.zip && unzip kotlin-hello-world-gradle.zip -d kotlin-hello-world-gradle && rm kotlin-hello-world-gradle.zip && cd kotlin-hello-world-gradle ``` -------------------------------- ### Vercel AI Chat Agent Installation and Usage Source: https://docs.restate.dev/ai/patterns/sessions Instructions and commands to install Restate, get the example, and run the chat agent. ```bash npm install --global @restatedev/restate-server@latest @restatedev/restate@latest restate-server ``` ```bash restate example typescript-vercel-ai-tour-of-agents && cd typescript-vercel-ai-tour-of-agents npm install ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash npx tsx ./src/chat-agent.ts ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/Chat/session123/message \ --json '{"message": "make a poem about durable execution"}' ``` ```bash curl localhost:8080/Chat/session123/message \ --json '{"message": "shorten it to 2 lines"}' ``` ```bash curl localhost:8080/Chat/session456/message \ --json '{"message": "what are the benefits of durable execution?"}' ``` -------------------------------- ### Create an Encore app Source: https://docs.restate.dev/guides/encore Follow the Encore quickstart to install the CLI, then create a new app. ```shell encore app create ``` -------------------------------- ### Restate Py Source: https://docs.restate.dev/ai/patterns/competitive-racing This code snippet demonstrates how to race multiple AI models concurrently using Restate Py. It starts two service calls, waits for the first one to complete, and cancels the other. The example includes installation, setup, and execution instructions. ```python racing_agent = Service("RacingAgent") @racing_agent.handler() async def run(ctx: Context, query: Question) -> str | None: """Run two approaches in parallel and return the fastest response.""" # Start both service calls concurrently slow_response = ctx.service_call(think_longer, arg=query) quick_response = ctx.service_call(respond_quickly, arg=query) done, pending = await restate.wait_completed(slow_response, quick_response) # cancel the pending calls for f in pending: call_future = typing.cast(RestateDurableCallFuture, f) ctx.cancel_invocation(await call_future.invocation_id()) # return the fastest result return await done[0] ``` ```bash restate-server ``` ```bash restate example python-restate-tour-of-agents && cd python-restate-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/racing_agents.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/RacingAgent/run \ --json '{ "message": "What is the best approach to learn machine learning?" }' ``` -------------------------------- ### Restate TS Source: https://docs.restate.dev/ai/patterns/competitive-racing This code snippet demonstrates how to race multiple AI models concurrently using Restate TS. It starts two service calls, waits for the first one to complete, and cancels the other. The example includes installation, setup, and execution instructions. ```typescript async function run( ctx: Context, { message }: { message: string }, ): Promise { // Start both service calls concurrently const slowCall = ctx.serviceClient(racingAgent).thinkLonger({ message }); const slowResponse = slowCall.map((res) => ({ tag: "slow", res })); const fastCall = ctx.serviceClient(racingAgent).respondQuickly({ message }); const fastResponse = fastCall.map((res) => ({ tag: "fast", res })); const pending = [slowResponse, fastResponse]; // Wait for the first one to complete const { tag, res } = await RestatePromise.any(pending); if (tag === "fast") { console.log("Quick response won the race!"); const slowInvocationId = await slowCall.invocationId; ctx.cancel(slowInvocationId); } else { console.log("Deep analysis won the race!"); const quickInvocationId = await fastCall.invocationId; ctx.cancel(quickInvocationId); } return res ?? "LLM gave no response"; } ``` ```bash restate-server ``` ```bash restate example typescript-restate-tour-of-agents && cd typescript-restate-tour-of-agents npm install ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash npx tsx ./src/racing-agents.ts ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/RacingAgent/run \ --json '{ "message": "What is the best approach to learn machine learning?" }' ``` -------------------------------- ### Run the Greeter service Source: https://docs.restate.dev/get_started/quickstart?sdk=kotlin Builds and runs the Greeter service using Gradle, listening on port 9080. ```bash ./gradlew bootRun ``` -------------------------------- ### Install and Run Restate Source: https://docs.restate.dev/llms-full.txt Instructions to install Restate, get the example, set up API keys, and run the workflow orchestrator. ```bash restate-server ``` ```bash restate example python-restate-tour-of-agents && cd python-restate-tour-of-agents ``` ```bash export OPENAI_API_KEY=sk-... ``` ```bash uv run app/workflow_orchestrator.py ``` ```bash restate deployments register http://localhost:9080 --force --yes # dev only: overrides previous registrations ``` ```bash curl localhost:8080/ResearchReport/generate \ --json '{"topic": "The impact of renewable energy on global economies"}' ``` -------------------------------- ### Run the Greeter service Source: https://docs.restate.dev/get_started/quickstart Builds and runs the Greeter service using Gradle. ```bash ./gradlew run ```