Spaces:
Running
Running
File size: 2,832 Bytes
0e9396b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
"""
Echo Environment Client.
This module provides the client for connecting to an Echo Environment server.
EchoEnv extends MCPToolClient to provide tool-calling style interactions.
Example:
>>> with EchoEnv(base_url="http://localhost:8000") as env:
... env.reset()
...
... # Discover tools
... tools = env.list_tools()
... print([t.name for t in tools]) # ['echo_message', 'echo_with_length']
...
... # Call tools
... result = env.call_tool("echo_message", message="Hello!")
... print(result) # "Hello!"
...
... result = env.call_tool("echo_with_length", message="Test")
... print(result) # {"message": "Test", "length": 4}
"""
from openenv.core.mcp_client import MCPToolClient
class EchoEnv(MCPToolClient):
"""
Client for the Echo Environment.
This client provides a simple interface for interacting with the Echo
Environment via MCP tools. It inherits all functionality from MCPToolClient:
- `list_tools()`: Discover available tools
- `call_tool(name, **kwargs)`: Call a tool by name
- `reset(**kwargs)`: Reset the environment
- `step(action)`: Execute an action (for advanced use)
Example:
>>> # Connect to a running server
>>> with EchoEnv(base_url="http://localhost:8000") as env:
... env.reset()
...
... # List available tools
... tools = env.list_tools()
... for tool in tools:
... print(f"{tool.name}: {tool.description}")
...
... # Echo a message
... result = env.call_tool("echo_message", message="Hello!")
... print(result) # "Hello!"
...
... # Echo with length
... result = env.call_tool("echo_with_length", message="Test")
... print(result) # {"message": "Test", "length": 4}
Example with Docker:
>>> # Automatically start container and connect
>>> env = EchoEnv.from_docker_image("echo-env:latest")
>>> try:
... env.reset()
... tools = env.list_tools()
... result = env.call_tool("echo_message", message="Hello!")
... finally:
... env.close()
Example with HuggingFace Space:
>>> # Run from HuggingFace Space
>>> env = EchoEnv.from_env("openenv/echo-env")
>>> try:
... env.reset()
... result = env.call_tool("echo_message", message="Hello!")
... finally:
... env.close()
"""
pass # MCPToolClient provides all needed functionality
|