forked from Rath-Team/OpenRath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_hello_agent.py
More file actions
39 lines (27 loc) · 1.13 KB
/
Copy path01_hello_agent.py
File metadata and controls
39 lines (27 loc) · 1.13 KB
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
"""01 · Hello, Agent — the smallest OpenRath program.
`flow.Agent` is OpenRath's `nn.Module`: build it once with a system prompt and
a provider, then *call* it on a `Session` (the "tensor") to get an updated
session back. This is the canonical entry point — most examples build on it.
Run:
python example/01_hello_agent.py
Needs an OpenAI-compatible key: export ``OPENAI_API_KEY`` (and optionally
``OPENAI_BASE_URL`` / ``OPENAI_DEFAULT_MODEL``), or configure
``llm.default_provider`` in ``~/.openrath/config.json``.
"""
from __future__ import annotations
from _shared import provider_from_env, stream_to_stdout
from rath import flow
from rath.session import Session
def main() -> None:
agent = flow.Agent(
"You are a concise assistant.",
provider_from_env(),
on_event=stream_to_stdout(),
)
user = Session.from_user_message("In one sentence, what is OpenRath?").to("local")
out = agent(user)
print() # newline after the streamed answer
if out.cumulative_usage is not None:
print(f"--- tokens: total={out.cumulative_usage.total_tokens}")
if __name__ == "__main__":
main()