Python SDK for the Open Reward Standard (ORS) — an HTTP protocol for connecting AI agents to RL environments
Project description
ORS SDK
Python SDK for the Open Reward Standard (ORS) — an HTTP-based protocol for connecting AI agents to reinforcement learning environments.
Installation
pip install ors-sdk
Quick Start
Server (hosting an environment)
from pydantic import BaseModel
from ors import Environment, Server, tool, ToolOutput, TextBlock, Split
class SubmitInput(BaseModel):
answer: str
class MathEnv(Environment):
@classmethod
def list_splits(cls):
return [Split(name="test", type="test")]
@classmethod
def list_tasks(cls, split: str):
return [{"question": "What is 2+2?", "answer": "4"}]
def get_prompt(self):
return [TextBlock(text=self.task_spec["question"])]
@tool
def submit(self, params: SubmitInput) -> ToolOutput:
correct = params.answer.strip() == self.task_spec["answer"]
return ToolOutput(
blocks=[TextBlock(text="Correct!" if correct else "Incorrect")],
reward=1.0 if correct else 0.0,
finished=True,
)
if __name__ == "__main__":
Server([MathEnv]).run(port=8080)
Client (connecting to an environment)
from ors.client import ORS
client = ORS(base_url="http://localhost:8080")
env = client.environment("mathenv")
tasks = env.list_tasks(split="test")
with env.session(task=tasks[0]) as session:
prompt = session.get_prompt()
print(f"Question: {prompt[0].text}")
result = session.call_tool("submit", {"answer": "4"})
print(f"Reward: {result.reward}, Finished: {result.finished}")
Links
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ors_sdk-0.1.0.tar.gz
(30.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ors_sdk-0.1.0-py3-none-any.whl
(31.4 kB
view details)
File details
Details for the file ors_sdk-0.1.0.tar.gz.
File metadata
- Download URL: ors_sdk-0.1.0.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2364c4569c772fdf24b57644a606875ff5900e3ba167b81e38616177784446b1
|
|
| MD5 |
e638007765b1b8e15b65b51f52dad6aa
|
|
| BLAKE2b-256 |
988e2f052c8ea1b33b6299cf7d35deb62e1256c1c33d338215772635733367eb
|
File details
Details for the file ors_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ors_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62fbf348f9875e975a2d961135cba140bc6f9f8c4c07955f69d9e97ec25acb66
|
|
| MD5 |
be2a86c41da684ee50da3670255ec178
|
|
| BLAKE2b-256 |
2ec71818ede0a134868cf2c29362f42a48376f37642641b78df75ca1678b7f4f
|