Skip to content

Commit ef05f96

Browse files
authored
fix echo environment docs examples (#908)
1 parent a53bc55 commit ef05f96

3 files changed

Lines changed: 102 additions & 65 deletions

File tree

docs/source/environments/echo.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ The simplest way to use the Echo environment is through the `EchoEnv` class. The
99

1010
```python
1111
import asyncio
12-
from echo_env import EchoAction, EchoEnv
12+
from echo_env import CallToolAction, EchoEnv
1313

1414
async def main():
1515
# Create environment from Docker image
1616
client = await EchoEnv.from_docker_image("echo-env:latest")
1717

1818
async with client:
19-
# Reset
20-
result = await client.reset()
21-
print(f"Reset: {result.observation.echoed_message}")
19+
await client.reset()
2220

2321
# Send multiple messages
2422
messages = ["Hello, World!", "Testing echo", "Final message"]
2523

2624
for msg in messages:
27-
result = await client.step(EchoAction(message=msg))
25+
result = await client.step(
26+
CallToolAction(
27+
tool_name="echo_message",
28+
arguments={"message": msg},
29+
)
30+
)
2831
print(f"Sent: '{msg}'")
29-
print(f" → Echoed: '{result.observation.echoed_message}'")
30-
print(f" → Length: {result.observation.message_length}")
32+
print(f" → Echoed: '{result.observation.result}'")
3133
print(f" → Reward: {result.reward}")
3234

3335
asyncio.run(main())
@@ -36,12 +38,17 @@ asyncio.run(main())
3638
For **synchronous usage**, use the `.sync()` wrapper:
3739

3840
```python
39-
from echo_env import EchoAction, EchoEnv
41+
from echo_env import CallToolAction, EchoEnv
4042

4143
with EchoEnv(base_url="http://localhost:8000").sync() as client:
42-
result = client.reset()
43-
result = client.step(EchoAction(message="Hello!"))
44-
print(result.observation.echoed_message)
44+
client.reset()
45+
result = client.step(
46+
CallToolAction(
47+
tool_name="echo_message",
48+
arguments={"message": "Hello!"},
49+
)
50+
)
51+
print(result.observation.result)
4552
```
4653

4754
The `EchoEnv.from_docker_image()` method handles:
@@ -61,23 +68,20 @@ docker build -t echo-env:latest -f envs/echo_env/server/Dockerfile .
6168

6269
## Environment Details
6370

64-
### Action
65-
**EchoAction**: Contains a single field
66-
- `message` (str) - The message to echo back
71+
### Tools
72+
- `echo_message(message)` - Echo the provided message
73+
- `echo_with_length(message)` - Echo the message and include its length
6774

6875
### Observation
69-
**EchoObservation**: Contains the echo response and metadata
70-
- `echoed_message` (str) - The message echoed back
71-
- `message_length` (int) - Length of the message
72-
- `reward` (float) - Reward based on message length (length × 0.1)
73-
- `done` (bool) - Always False for echo environment
76+
**CallToolObservation**: Contains the tool result and metadata
77+
- `result` - The tool return value
78+
- `reward` (float) - Reward returned by the environment
79+
- `done` (bool) - Always `False` for the echo environment
7480
- `metadata` (dict) - Additional info like step count
7581

7682
### Reward
77-
The reward is calculated as: `message_length × 0.1`
78-
- "Hi" → reward: 0.2
79-
- "Hello, World!" → reward: 1.3
80-
- Empty message → reward: 0.0
83+
The echo environment returns `0.0` reward for tool calls. It is intended as a
84+
minimal MCP integration example rather than a reward-shaping reference.
8185

8286
## Advanced Usage
8387

@@ -86,17 +90,27 @@ The reward is calculated as: `message_length × 0.1`
8690
If you already have an Echo environment server running, you can connect directly:
8791

8892
```python
89-
from echo_env import EchoAction, EchoEnv
93+
from echo_env import CallToolAction, EchoEnv
9094

9195
# Async usage
9296
async with EchoEnv(base_url="http://localhost:8000") as client:
93-
result = await client.reset()
94-
result = await client.step(EchoAction(message="Hello!"))
97+
await client.reset()
98+
result = await client.step(
99+
CallToolAction(
100+
tool_name="echo_message",
101+
arguments={"message": "Hello!"},
102+
)
103+
)
95104

96105
# Sync usage
97106
with EchoEnv(base_url="http://localhost:8000").sync() as client:
98-
result = client.reset()
99-
result = client.step(EchoAction(message="Hello!"))
107+
client.reset()
108+
result = client.step(
109+
CallToolAction(
110+
tool_name="echo_message",
111+
arguments={"message": "Hello!"},
112+
)
113+
)
100114
```
101115

102116
Note: When connecting to an existing server, closing the client will NOT stop the server.

docs/source/getting-started.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ parallel environment runs, and integrations with async frameworks.
5858
```python
5959
import asyncio
6060

61-
from echo_env import EchoAction, EchoEnv
61+
from echo_env import CallToolAction, EchoEnv
6262

6363

6464
async def main():
6565
async with EchoEnv(base_url="https://openenv-echo-env.hf.space") as client:
66-
result = await client.reset()
67-
print(result.observation.echoed_message)
68-
69-
result = await client.step(EchoAction(message="Hello, World!"))
66+
await client.reset()
67+
68+
result = await client.step(
69+
CallToolAction(
70+
tool_name="echo_message",
71+
arguments={"message": "Hello, World!"},
72+
)
73+
)
7074
print(result.reward)
7175

7276

@@ -76,12 +80,17 @@ asyncio.run(main())
7680
For scripts and notebooks, use `.sync()`:
7781

7882
```python
79-
from echo_env import EchoAction, EchoEnv
83+
from echo_env import CallToolAction, EchoEnv
8084

8185
with EchoEnv(base_url="https://openenv-echo-env.hf.space").sync() as client:
82-
result = client.reset()
83-
result = client.step(EchoAction(message="Hello, World!"))
84-
print(result.observation.echoed_message)
86+
client.reset()
87+
result = client.step(
88+
CallToolAction(
89+
tool_name="echo_message",
90+
arguments={"message": "Hello, World!"},
91+
)
92+
)
93+
print(result.observation.result)
8594
```
8695

8796
## Use Containers or Local Servers

envs/echo_env/README.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@ The simplest way to use the Echo environment is through the `EchoEnv` class. The
2121

2222
```python
2323
import asyncio
24-
from echo_env import EchoAction, EchoEnv
24+
from echo_env import CallToolAction, EchoEnv
2525

2626
async def main():
2727
# Create environment from Docker image
2828
client = await EchoEnv.from_docker_image("echo-env:latest")
2929

3030
async with client:
31-
# Reset
32-
result = await client.reset()
33-
print(f"Reset: {result.observation.echoed_message}")
31+
await client.reset()
3432

3533
# Send multiple messages
3634
messages = ["Hello, World!", "Testing echo", "Final message"]
3735

3836
for msg in messages:
39-
result = await client.step(EchoAction(message=msg))
37+
result = await client.step(
38+
CallToolAction(
39+
tool_name="echo_message",
40+
arguments={"message": msg},
41+
)
42+
)
4043
print(f"Sent: '{msg}'")
41-
print(f" → Echoed: '{result.observation.echoed_message}'")
42-
print(f" → Length: {result.observation.message_length}")
44+
print(f" → Echoed: '{result.observation.result}'")
4345
print(f" → Reward: {result.reward}")
4446

4547
asyncio.run(main())
@@ -48,12 +50,17 @@ asyncio.run(main())
4850
For **synchronous usage**, use the `.sync()` wrapper:
4951

5052
```python
51-
from echo_env import EchoAction, EchoEnv
53+
from echo_env import CallToolAction, EchoEnv
5254

5355
with EchoEnv(base_url="http://localhost:8000").sync() as client:
54-
result = client.reset()
55-
result = client.step(EchoAction(message="Hello!"))
56-
print(result.observation.echoed_message)
56+
client.reset()
57+
result = client.step(
58+
CallToolAction(
59+
tool_name="echo_message",
60+
arguments={"message": "Hello!"},
61+
)
62+
)
63+
print(result.observation.result)
5764
```
5865

5966
The `EchoEnv.from_docker_image()` method handles:
@@ -73,23 +80,20 @@ docker build -t echo-env:latest -f envs/echo_env/server/Dockerfile .
7380

7481
## Environment Details
7582

76-
### Action
77-
**EchoAction**: Contains a single field
78-
- `message` (str) - The message to echo back
83+
### Tools
84+
- `echo_message(message)` - Echo the provided message
85+
- `echo_with_length(message)` - Echo the message and include its length
7986

8087
### Observation
81-
**EchoObservation**: Contains the echo response and metadata
82-
- `echoed_message` (str) - The message echoed back
83-
- `message_length` (int) - Length of the message
84-
- `reward` (float) - Reward based on message length (length × 0.1)
85-
- `done` (bool) - Always False for echo environment
88+
**CallToolObservation**: Contains the tool result and metadata
89+
- `result` - The tool return value
90+
- `reward` (float) - Reward returned by the environment
91+
- `done` (bool) - Always `False` for the echo environment
8692
- `metadata` (dict) - Additional info like step count
8793

8894
### Reward
89-
The reward is calculated as: `message_length × 0.1`
90-
- "Hi" → reward: 0.2
91-
- "Hello, World!" → reward: 1.3
92-
- Empty message → reward: 0.0
95+
The echo environment returns `0.0` reward for tool calls. It is intended as a
96+
minimal MCP integration example rather than a reward-shaping reference.
9397

9498
## Advanced Usage
9599

@@ -98,17 +102,27 @@ The reward is calculated as: `message_length × 0.1`
98102
If you already have an Echo environment server running, you can connect directly:
99103

100104
```python
101-
from echo_env import EchoAction, EchoEnv
105+
from echo_env import CallToolAction, EchoEnv
102106

103107
# Async usage
104108
async with EchoEnv(base_url="http://localhost:8000") as client:
105-
result = await client.reset()
106-
result = await client.step(EchoAction(message="Hello!"))
109+
await client.reset()
110+
result = await client.step(
111+
CallToolAction(
112+
tool_name="echo_message",
113+
arguments={"message": "Hello!"},
114+
)
115+
)
107116

108117
# Sync usage
109118
with EchoEnv(base_url="http://localhost:8000").sync() as client:
110-
result = client.reset()
111-
result = client.step(EchoAction(message="Hello!"))
119+
client.reset()
120+
result = client.step(
121+
CallToolAction(
122+
tool_name="echo_message",
123+
arguments={"message": "Hello!"},
124+
)
125+
)
112126
```
113127

114128
Note: When connecting to an existing server, closing the client will NOT stop the server.

0 commit comments

Comments
 (0)