├── .gitignore ├── .prettierrc ├── CHANGELOG.md ├── README.md ├── index.html ├── lib ├── agent-context.tsx ├── get-path-prefix.ts ├── index.ts ├── use-agent-context.ts ├── use-agent-debug.ts ├── use-agent-memo.ts ├── use-agent-state.ts ├── use-agent-tool.ts ├── use-agent.ts └── zod-parse-json.ts ├── package-lock.json ├── package.json ├── src ├── demos │ ├── agentic-counter │ │ ├── index.css │ │ ├── index.html │ │ └── main.jsx │ ├── hierarchy │ │ ├── index.css │ │ ├── index.html │ │ └── main.jsx │ └── john-age-changer │ │ ├── index.css │ │ ├── index.html │ │ └── main.jsx ├── index.css ├── main.jsx └── vite-env.d.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.lib.json ├── tsconfig.node.json └── vite.config.ts /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120 3 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # v1.0.0-beta.27 2 | 3 | - Breaking change: `useAgent` now returns a simplified `run` method with agent lifecycle hooks as parameters 4 | - Added: `status` property in the agent returned by `useAgent` 5 | 6 | # v1.0.0-beta.25 7 | 8 | - Changed: parallel tool-use is disabled by default 9 | 10 | # v1.0.0-beta.24 11 | 12 | - Changed: improve tool rendering to agent 13 | 14 | # v1.0.0-beta.23 15 | 16 | - Added: `useAgentContext` for building custom agents 17 | 18 | # v1.0.0-beta.22 19 | 20 | - Added: tool name auto-aliasing so you can use the same tool name with different implementations 21 | 22 | # v1.0.0-beta.20 23 | 24 | - Added: partial support `AgentContext` to allow hierarchical organization of agents 25 | - Changed: improved state and tool description for agent 26 | - Fixed: some characters in tool name will cause error 27 | 28 | # v1.0.0-beta.19 29 | 30 | - Added: `description` field for state hook 31 | - Added: model override 32 | 33 | # v1.0.0-beta.18 34 | 35 | - Added: require `dependencies` for memo to prevent infinite loops 36 | 37 | # v1.0.0-beta.17 38 | 39 | - Added: abortable agent runs 40 | 41 | # v1.0.0-beta.16 42 | 43 | - Added: `dependencies` field in memo and tool hooks options 44 | - Added: `description` field in tool hook option 45 | 46 | # v1.0.0-beta.14 47 | 48 | - Added: `enabled` option in all the hooks to dynamically show/hide state/tool 49 | - Added: `useAgentContext` hook to expose tools and states for building a custom agent 50 | 51 | # v1.0.0-beta.9 52 | 53 | - Initial beta release 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Agent Hooks 2 | 3 | | Agentic Counter Demo | Agentic Todo Demo | 4 | | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 5 | | [](https://stackblitz.com/edit/react-agentic-counter?file=src%2Fmain.jsx) | [](https://stackblitz.com/github/chuanqisun/react-agent-hooks?file=src%2Fmain.jsx) | 6 | 7 | Turn React Hooks into LLM Tools 8 | 9 | - 🪝 Familiar: same semantics as React hooks 10 | - 🤝 Symbiotic: human interface and Agent interface derived from the same state. 11 | - 🛡️ Safe: developer controls the schema for Agentic state change. 12 | - ➕ Incremental adoption: use as much or as little as you want. 13 | - 📦 Composable: fully interoperable with classic React hooks. 14 | - 🔮 Future-ready: forward-compatible with MCP and llms.txt. 15 | 16 | **Before** 17 | 18 | ```jsx 19 | import { useCallback, useState } from "react"; 20 | 21 | function MyComponent() { 22 | const [name, setName] = useState("John Doe"); 23 | const [age, setAge] = useState(30); 24 | const adjust = useCallback((delta) => setAge((prev) => prev + delta), []); 25 | 26 | return ( 27 |
{age}
30 | 31 | 32 |{age}
53 | 54 | 55 |{age}
86 |