@agentick/core 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +58 -13
  2. package/dist/.tsbuildinfo.build +1 -1
  3. package/dist/agentick-instance.d.ts.map +1 -1
  4. package/dist/agentick-instance.js +3 -2
  5. package/dist/agentick-instance.js.map +1 -1
  6. package/dist/app/session.d.ts +6 -1
  7. package/dist/app/session.d.ts.map +1 -1
  8. package/dist/app/session.js +80 -53
  9. package/dist/app/session.js.map +1 -1
  10. package/dist/app/types.d.ts +53 -37
  11. package/dist/app/types.d.ts.map +1 -1
  12. package/dist/com/object-model.d.ts.map +1 -1
  13. package/dist/com/object-model.js +8 -3
  14. package/dist/com/object-model.js.map +1 -1
  15. package/dist/compiler/collector.d.ts.map +1 -1
  16. package/dist/compiler/collector.js +14 -5
  17. package/dist/compiler/collector.js.map +1 -1
  18. package/dist/compiler/fiber-compiler.d.ts +2 -0
  19. package/dist/compiler/fiber-compiler.d.ts.map +1 -1
  20. package/dist/compiler/fiber-compiler.js +29 -1
  21. package/dist/compiler/fiber-compiler.js.map +1 -1
  22. package/dist/compiler/index.d.ts +1 -1
  23. package/dist/compiler/index.d.ts.map +1 -1
  24. package/dist/compiler/index.js.map +1 -1
  25. package/dist/compiler/structure-renderer.d.ts.map +1 -1
  26. package/dist/compiler/structure-renderer.js +4 -15
  27. package/dist/compiler/structure-renderer.js.map +1 -1
  28. package/dist/compiler/types.d.ts +2 -10
  29. package/dist/compiler/types.d.ts.map +1 -1
  30. package/dist/compiler/types.js.map +1 -1
  31. package/dist/engine/tool-executor.js +3 -3
  32. package/dist/engine/tool-executor.js.map +1 -1
  33. package/dist/hooks/index.d.ts +2 -2
  34. package/dist/hooks/index.d.ts.map +1 -1
  35. package/dist/hooks/index.js +2 -2
  36. package/dist/hooks/index.js.map +1 -1
  37. package/dist/hooks/knob.d.ts +12 -0
  38. package/dist/hooks/knob.d.ts.map +1 -1
  39. package/dist/hooks/knob.js +32 -2
  40. package/dist/hooks/knob.js.map +1 -1
  41. package/dist/hooks/knobs-component.d.ts +1 -0
  42. package/dist/hooks/knobs-component.d.ts.map +1 -1
  43. package/dist/hooks/knobs-component.js +5 -1
  44. package/dist/hooks/knobs-component.js.map +1 -1
  45. package/dist/hooks/lifecycle.d.ts +21 -14
  46. package/dist/hooks/lifecycle.d.ts.map +1 -1
  47. package/dist/hooks/lifecycle.js +32 -13
  48. package/dist/hooks/lifecycle.js.map +1 -1
  49. package/dist/hooks/runtime-context.d.ts +12 -1
  50. package/dist/hooks/runtime-context.d.ts.map +1 -1
  51. package/dist/hooks/runtime-context.js +21 -0
  52. package/dist/hooks/runtime-context.js.map +1 -1
  53. package/dist/hooks/types.d.ts +8 -0
  54. package/dist/hooks/types.d.ts.map +1 -1
  55. package/dist/hooks/types.js.map +1 -1
  56. package/dist/index.d.ts +2 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +1 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/jsx/jsx-runtime.d.ts +6 -0
  61. package/dist/jsx/jsx-runtime.d.ts.map +1 -1
  62. package/dist/jsx/jsx-runtime.js.map +1 -1
  63. package/dist/procedure/index.d.ts.map +1 -1
  64. package/dist/testing/compile-agent.d.ts +4 -3
  65. package/dist/testing/compile-agent.d.ts.map +1 -1
  66. package/dist/testing/compile-agent.js +2 -2
  67. package/dist/testing/compile-agent.js.map +1 -1
  68. package/dist/testing/index.d.ts +2 -2
  69. package/dist/testing/index.d.ts.map +1 -1
  70. package/dist/testing/index.js +2 -2
  71. package/dist/testing/index.js.map +1 -1
  72. package/dist/testing/{test-environment.d.ts → test-runner.d.ts} +26 -26
  73. package/dist/testing/test-runner.d.ts.map +1 -0
  74. package/dist/testing/{test-environment.js → test-runner.js} +21 -21
  75. package/dist/testing/test-runner.js.map +1 -0
  76. package/dist/tool/tool.d.ts +60 -2
  77. package/dist/tool/tool.d.ts.map +1 -1
  78. package/dist/tool/tool.js +90 -20
  79. package/dist/tool/tool.js.map +1 -1
  80. package/dist/utils/token-estimate.d.ts +4 -3
  81. package/dist/utils/token-estimate.d.ts.map +1 -1
  82. package/dist/utils/token-estimate.js +16 -15
  83. package/dist/utils/token-estimate.js.map +1 -1
  84. package/package.json +3 -3
  85. package/dist/testing/test-environment.d.ts.map +0 -1
  86. package/dist/testing/test-environment.js.map +0 -1
package/README.md CHANGED
@@ -592,6 +592,18 @@ const WeatherTool = createTool({
592
592
  render: (tickState, ctx) => <Section id="weather-info">Last checked: {lastChecked}</Section>,
593
593
  });
594
594
 
595
+ // Tools can capture tree-scoped context via use():
596
+ const ShellTool = createTool({
597
+ name: "shell",
598
+ description: "Execute a command in the sandbox",
599
+ input: z.object({ command: z.string() }),
600
+ use: () => ({ sandbox: useSandbox() }), // runs at render time
601
+ handler: async ({ command }, deps) => {
602
+ const result = await deps!.sandbox.exec(command);
603
+ return [{ type: "text", text: result.stdout }];
604
+ },
605
+ });
606
+
595
607
  // Use in your app
596
608
  function App() {
597
609
  return (
@@ -604,6 +616,39 @@ function App() {
604
616
  }
605
617
  ```
606
618
 
619
+ ### Prop Overrides
620
+
621
+ Customize pre-built tool metadata via JSX props without creating new tools:
622
+
623
+ ```tsx
624
+ <WeatherTool description="Check weather. Always include units." />
625
+ <ShellTool name="bash" requiresConfirmation={true} />
626
+ ```
627
+
628
+ ### Tool Sources
629
+
630
+ Tools merge from four sources (lowest → highest priority):
631
+
632
+ ```tsx
633
+ // 1. App-level — available to all sessions
634
+ const app = createApp(Agent, { tools: [SearchTool] });
635
+
636
+ // 2. Session-level — available for this session
637
+ const session = await app.session({ tools: [FileTool] });
638
+
639
+ // 3. Per-execution — available only during this send()
640
+ await session.send({ messages: [...], tools: [DynamicTool] });
641
+
642
+ // 4. JSX-reconciled — highest priority, re-evaluated each tick
643
+ function Agent() {
644
+ return <SearchTool description="Custom desc" />;
645
+ }
646
+ ```
647
+
648
+ On each tick, tools merge in order: app → session → execution → JSX. Last-in wins by name.
649
+
650
+ Spawned sessions (`session.spawn()`) start fresh — they do **not** inherit parent tools. Each child defines its own toolset via JSX and app-level tools.
651
+
607
652
  ## App & Session
608
653
 
609
654
  ### Creating an App
@@ -626,7 +671,7 @@ const app = createApp(MyApp, {
626
671
  devTools: true, // Enable DevTools emission
627
672
  tools: [ExternalTool], // Additional tools (merged with JSX <Tool>s)
628
673
  mcpServers: { ... }, // MCP server configs
629
- environment: myEnv, // Execution environment (see below)
674
+ runner: myRunner, // Execution runner (see below)
630
675
  });
631
676
  ```
632
677
 
@@ -961,19 +1006,19 @@ await run(<Agent query="default" />, { props: { query: "override" }, model, mess
961
1006
 
962
1007
  `createApp` takes a component function and returns a reusable app with session management, persistence, and middleware support.
963
1008
 
964
- ## Execution Environments
1009
+ ## Execution Runners
965
1010
 
966
- An `ExecutionEnvironment` controls the execution backend — how compiled context reaches the model and how tool calls are routed. The default is the standard model → tool_use protocol. Swap in a different environment to change the entire execution model without touching your agent code.
1011
+ An `ExecutionRunner` controls the execution backend — how compiled context reaches the model and how tool calls are routed. The default is the standard model → tool_use protocol. Swap in a different runner to change the entire execution model without touching your agent code.
967
1012
 
968
1013
  ```tsx
969
- import { createApp, type ExecutionEnvironment } from "@agentick/core";
1014
+ import { createApp, type ExecutionRunner } from "@agentick/core";
970
1015
 
971
- const replEnvironment: ExecutionEnvironment = {
1016
+ const replRunner: ExecutionRunner = {
972
1017
  name: "repl",
973
1018
 
974
- // Transform what the model sees — replace tool schemas with prose descriptions,
1019
+ // Transform the compiled structure — replace tool schemas with prose descriptions,
975
1020
  // expose a single "execute" tool, restructure sections, anything.
976
- prepareModelInput(compiled, tools) {
1021
+ transformCompiled(compiled, tools) {
977
1022
  const commandList = tools
978
1023
  .map((t) => `- ${t.metadata?.name}: ${t.metadata?.description}`)
979
1024
  .join("\n");
@@ -1008,10 +1053,10 @@ const replEnvironment: ExecutionEnvironment = {
1008
1053
  };
1009
1054
 
1010
1055
  // Same agent, different execution model
1011
- const app = createApp(MyAgent, { model, environment: replEnvironment });
1056
+ const app = createApp(MyAgent, { model, runner: replRunner });
1012
1057
  ```
1013
1058
 
1014
- The agent's JSX — its `<System>`, `<Timeline>`, `<Tool>` components — stays identical. The environment transforms how that compiled context is consumed and how tool calls execute. This means you can build one agent and run it against multiple backends: standard tool_use for production, a sandboxed REPL for code execution, a human-in-the-loop gateway for approval workflows.
1059
+ The agent's JSX — its `<System>`, `<Timeline>`, `<Tool>` components — stays identical. The runner transforms how that compiled context is consumed and how tool calls execute. This means you can build one agent and run it against multiple backends: standard tool_use for production, a sandboxed REPL for code execution, a human-in-the-loop gateway for approval workflows.
1015
1060
 
1016
1061
  ### Interface
1017
1062
 
@@ -1019,11 +1064,11 @@ All methods are optional. Omitted methods use default behavior.
1019
1064
 
1020
1065
  | Hook | Purpose | Timing |
1021
1066
  | ------------------- | --------------------------------------------------- | ------------- |
1022
- | `prepareModelInput` | Transform compiled context before the model sees it | Per tick |
1067
+ | `transformCompiled` | Transform compiled context before the model sees it | Per tick |
1023
1068
  | `executeToolCall` | Intercept, transform, or replace tool execution | Per tool call |
1024
1069
  | `onSessionInit` | Set up per-session resources (sandbox, workspace) | Once |
1025
- | `onPersist` | Add environment state to session snapshot | Per save |
1026
- | `onRestore` | Restore environment state from snapshot | Once |
1070
+ | `onPersist` | Add runner state to session snapshot | Per save |
1071
+ | `onRestore` | Restore runner state from snapshot | Once |
1027
1072
  | `onDestroy` | Clean up resources | Once |
1028
1073
 
1029
1074
  ### Use Cases
@@ -1031,7 +1076,7 @@ All methods are optional. Omitted methods use default behavior.
1031
1076
  - **REPL/Code Execution**: Replace tool schemas with command descriptions, route `execute` calls to a sandboxed runtime, persist sandbox state across sessions.
1032
1077
  - **Human-in-the-Loop**: Transform tool calls into approval requests, gate execution on human confirmation, log decisions.
1033
1078
  - **Sandboxing**: Run tools in isolated containers, inject security boundaries, audit tool invocations.
1034
- - **Testing**: Intercept specific tools to return canned responses, track all lifecycle calls for assertions. See `createTestEnvironment()` in `@agentick/core/testing`.
1079
+ - **Testing**: Intercept specific tools to return canned responses, track all lifecycle calls for assertions. See `createTestRunner()` in `@agentick/core/testing`.
1035
1080
 
1036
1081
  ## DevTools Integration
1037
1082