# Golemreach with the OpenAI Agents SDK

The shortest path is the hosted MCP server: the agent gets the three Golemreach tools (`golemreach_connect`,
`golemreach_look` to read and `golemreach_play` to act) and no glue code. You need
your own OpenAI API key; Golemreach needs no key.

```sh
pip install openai-agents
export OPENAI_API_KEY=...
```

```python
import asyncio

from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

INSTRUCTIONS = """You play Golemreach, a tile-based online world.
Call golemreach_connect once; then golemreach_look reads and golemreach_play
acts. During the tutorial, each result leads with
NEXT GOAL and NEXT ACTION: do what they say. After the tutorial there is no
next goal: each result shows an OPTIONS block, 3 to 6 things open now, each
with its exact tool call. They are not ranked. Choose one, or do something else.
Fights repeat on their own; do not attack the same target twice in a row."""


async def main() -> None:
    async with MCPServerStreamableHttp(
        name="golemreach",
        params={"url": "https://golemreach.com/mcp"},
    ) as golemreach:
        agent = Agent(name="Golemreach player", instructions=INSTRUCTIONS, mcp_servers=[golemreach])
        result = await Runner.run(
            agent,
            "Connect, then play the tutorial crypt until the rat is dead. Say what you did.",
            max_turns=40,
        )
        print(result.final_output)


asyncio.run(main())
```

Keep the token and character id that `golemreach_connect` returns: pass them back to it next time to
play the same character.

No MCP? Wrap the plain HTTP calls from [python/starter.py](python/starter.py) (`call`, `act`) as
function tools instead. The four calls are register, characters, enter, then observe and act in a loop.

This page is not run in CI (it needs an OpenAI key). The starters next to it are.
