File size: 888 Bytes
53d41ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from _core.llm import LLMClient
from _core.tools import ToolRegistry, make_calculator, make_web_search
from _core.ui import build_agent_app
from agent import ReActAgent


def run_fn(llm: LLMClient, user_input: str):
    tools = ToolRegistry()
    tools.register(make_calculator())
    tools.register(make_web_search())
    return ReActAgent(llm=llm, tools=tools).run(user_input)


demo = build_agent_app(
    title="ReAct from scratch",
    description=(
        "The Reasoning + Acting loop, built from first principles. The agent "
        "interleaves thinking, tool calls, and observations. Bring your own "
        "OpenRouter key — it stays in your browser session."
    ),
    input_label="Question",
    input_placeholder="What is 24 * 17? And who won the 2022 FIFA World Cup?",
    run_fn=run_fn,
    example="What is 24 * 17?",
)

if __name__ == "__main__":
    demo.launch()