flock-core 0.1.2__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.

Potentially problematic release.


This version of flock-core might be problematic. Click here for more details.

Files changed (407) hide show
  1. flock/__init__.py +1 -4
  2. flock/core/__init__.py +1 -7
  3. flock/core/context/context.py +182 -0
  4. flock/core/context/context_manager.py +34 -0
  5. flock/core/{context_vars.py → context/context_vars.py} +8 -6
  6. flock/core/execution/local_executor.py +27 -0
  7. flock/core/execution/temporal_executor.py +56 -0
  8. flock/core/flock.py +232 -208
  9. flock/core/flock_agent.py +574 -0
  10. flock/core/logging/__init__.py +2 -18
  11. flock/core/logging/formatters/base_formatter.py +36 -0
  12. flock/core/logging/formatters/formatter_factory.py +38 -0
  13. flock/core/logging/formatters/pprint_formatter.py +18 -0
  14. flock/core/logging/formatters/rich_formatters.py +132 -0
  15. flock/core/logging/formatters/theme_builder.py +480 -0
  16. flock/core/logging/formatters/themed_formatter.py +442 -0
  17. flock/core/logging/logging.py +141 -0
  18. flock/core/logging/telemetry.py +21 -0
  19. flock/core/logging/trace_and_logged.py +55 -0
  20. flock/core/mixin/dspy_integration.py +197 -0
  21. flock/core/mixin/prompt_parser.py +125 -0
  22. flock/core/registry/agent_registry.py +118 -0
  23. flock/core/tools/basic_tools.py +296 -98
  24. flock/core/tools/dev_tools/github.py +190 -0
  25. flock/core/util/cli_helper.py +25 -0
  26. flock/core/util/input_resolver.py +156 -0
  27. flock/core/util/serializable.py +93 -0
  28. flock/themes/3024-day.toml +39 -0
  29. flock/themes/3024-night.toml +77 -0
  30. flock/themes/aardvark-blue.toml +77 -0
  31. flock/themes/abernathy.toml +77 -0
  32. flock/themes/adventure.toml +77 -0
  33. flock/themes/adventuretime.toml +77 -0
  34. flock/themes/afterglow.toml +77 -0
  35. flock/themes/alabaster.toml +77 -0
  36. flock/themes/alienblood.toml +77 -0
  37. flock/themes/andromeda.toml +77 -0
  38. flock/themes/apple-classic.toml +77 -0
  39. flock/themes/apple-system-colors.toml +77 -0
  40. flock/themes/arcoiris.toml +77 -0
  41. flock/themes/argonaut copy.toml +77 -0
  42. flock/themes/argonaut.toml +39 -0
  43. flock/themes/arthur.toml +77 -0
  44. flock/themes/ateliersulphurpool.toml +77 -0
  45. flock/themes/atom.toml +38 -0
  46. flock/themes/atom_test.toml +65 -0
  47. flock/themes/atomonelight.toml +77 -0
  48. flock/themes/aurora.toml +77 -0
  49. flock/themes/ayu copy.toml +77 -0
  50. flock/themes/ayu-light.toml +77 -0
  51. flock/themes/ayu-mirage.toml +77 -0
  52. flock/themes/ayu.toml +39 -0
  53. flock/themes/banana-blueberry.toml +77 -0
  54. flock/themes/batman.toml +77 -0
  55. flock/themes/belafonte-day.toml +77 -0
  56. flock/themes/belafonte-night.toml +77 -0
  57. flock/themes/birdsofparadise.toml +77 -0
  58. flock/themes/blazer.toml +77 -0
  59. flock/themes/blue-matrix.toml +77 -0
  60. flock/themes/blueberrypie.toml +77 -0
  61. flock/themes/bluedolphin.toml +77 -0
  62. flock/themes/blulocodark.toml +77 -0
  63. flock/themes/blulocolight.toml +77 -0
  64. flock/themes/borland.toml +77 -0
  65. flock/themes/breeze.toml +77 -0
  66. flock/themes/bright-lights.toml +77 -0
  67. flock/themes/broadcast.toml +77 -0
  68. flock/themes/brogrammer.toml +77 -0
  69. flock/themes/builtin-dark.toml +77 -0
  70. flock/themes/builtin-light.toml +77 -0
  71. flock/themes/builtin-pastel-dark.toml +77 -0
  72. flock/themes/builtin-solarized-dark.toml +77 -0
  73. flock/themes/builtin-solarized-light.toml +77 -0
  74. flock/themes/builtin-tango-dark.toml +77 -0
  75. flock/themes/builtin-tango-light.toml +77 -0
  76. flock/themes/c64.toml +77 -0
  77. flock/themes/calamity.toml +77 -0
  78. flock/themes/catppuccin-frappe.toml +77 -0
  79. flock/themes/catppuccin-latte.toml +77 -0
  80. flock/themes/catppuccin-macchiato.toml +77 -0
  81. flock/themes/catppuccin-mocha.toml +77 -0
  82. flock/themes/cga.toml +77 -0
  83. flock/themes/chalk.toml +77 -0
  84. flock/themes/chalkboard.toml +77 -0
  85. flock/themes/challengerdeep.toml +77 -0
  86. flock/themes/chester.toml +77 -0
  87. flock/themes/ciapre.toml +77 -0
  88. flock/themes/clrs.toml +77 -0
  89. flock/themes/cobalt-neon.toml +77 -0
  90. flock/themes/cobalt2.toml +77 -0
  91. flock/themes/coffee-theme.toml +77 -0
  92. flock/themes/crayonponyfish.toml +77 -0
  93. flock/themes/cutiepro.toml +77 -0
  94. flock/themes/cyberdyne.toml +77 -0
  95. flock/themes/cyberpunk.toml +77 -0
  96. flock/themes/cyberpunkscarletprotocol.toml +77 -0
  97. flock/themes/dark+.toml +77 -0
  98. flock/themes/dark-pastel.toml +77 -0
  99. flock/themes/darkermatrix.toml +77 -0
  100. flock/themes/darkmatrix.toml +77 -0
  101. flock/themes/darkside.toml +77 -0
  102. flock/themes/dayfox.toml +77 -0
  103. flock/themes/deep.toml +77 -0
  104. flock/themes/desert.toml +77 -0
  105. flock/themes/dimidium.toml +77 -0
  106. flock/themes/dimmedmonokai.toml +77 -0
  107. flock/themes/django.toml +77 -0
  108. flock/themes/djangorebornagain.toml +77 -0
  109. flock/themes/djangosmooth.toml +77 -0
  110. flock/themes/doom-peacock.toml +77 -0
  111. flock/themes/doomone.toml +77 -0
  112. flock/themes/dotgov.toml +77 -0
  113. flock/themes/dracula+.toml +77 -0
  114. flock/themes/dracula.toml +77 -0
  115. flock/themes/duckbones.toml +77 -0
  116. flock/themes/duotone-dark.toml +77 -0
  117. flock/themes/earthsong.toml +77 -0
  118. flock/themes/elemental.toml +77 -0
  119. flock/themes/elementary.toml +77 -0
  120. flock/themes/encom.toml +77 -0
  121. flock/themes/espresso-libre.toml +77 -0
  122. flock/themes/espresso.toml +77 -0
  123. flock/themes/everblush.toml +77 -0
  124. flock/themes/fahrenheit.toml +77 -0
  125. flock/themes/fairyfloss.toml +77 -0
  126. flock/themes/farmhouse-dark.toml +77 -0
  127. flock/themes/farmhouse-light.toml +77 -0
  128. flock/themes/fideloper.toml +77 -0
  129. flock/themes/firefly-traditional.toml +77 -0
  130. flock/themes/firefoxdev.toml +77 -0
  131. flock/themes/firewatch.toml +77 -0
  132. flock/themes/fishtank.toml +77 -0
  133. flock/themes/flat.toml +77 -0
  134. flock/themes/flatland.toml +77 -0
  135. flock/themes/flexoki-dark.toml +77 -0
  136. flock/themes/flexoki-light.toml +77 -0
  137. flock/themes/floraverse.toml +77 -0
  138. flock/themes/forestblue.toml +77 -0
  139. flock/themes/framer.toml +77 -0
  140. flock/themes/frontenddelight.toml +77 -0
  141. flock/themes/funforrest.toml +77 -0
  142. flock/themes/galaxy.toml +77 -0
  143. flock/themes/galizur.toml +77 -0
  144. flock/themes/github-dark.toml +77 -0
  145. flock/themes/github.toml +77 -0
  146. flock/themes/glacier.toml +77 -0
  147. flock/themes/grape.toml +77 -0
  148. flock/themes/grass.toml +77 -0
  149. flock/themes/grey-green.toml +77 -0
  150. flock/themes/gruber-darker.toml +77 -0
  151. flock/themes/gruvboxdark.toml +77 -0
  152. flock/themes/gruvboxdarkhard.toml +77 -0
  153. flock/themes/gruvboxlight.toml +77 -0
  154. flock/themes/guezwhoz.toml +77 -0
  155. flock/themes/hacktober.toml +77 -0
  156. flock/themes/hardcore.toml +77 -0
  157. flock/themes/harper.toml +77 -0
  158. flock/themes/hax0r-blue.toml +77 -0
  159. flock/themes/hax0r-gr33n.toml +77 -0
  160. flock/themes/hax0r-r3d.toml +77 -0
  161. flock/themes/highway.toml +77 -0
  162. flock/themes/hipster-green.toml +77 -0
  163. flock/themes/hivacruz.toml +77 -0
  164. flock/themes/homebrew.toml +77 -0
  165. flock/themes/hopscotch.256.toml +77 -0
  166. flock/themes/hopscotch.toml +77 -0
  167. flock/themes/hurtado.toml +77 -0
  168. flock/themes/hybrid.toml +77 -0
  169. flock/themes/ic-green-ppl.toml +77 -0
  170. flock/themes/ic-orange-ppl.toml +77 -0
  171. flock/themes/iceberg-dark.toml +77 -0
  172. flock/themes/iceberg-light.toml +77 -0
  173. flock/themes/idea.toml +77 -0
  174. flock/themes/idletoes.toml +77 -0
  175. flock/themes/ir-black.toml +77 -0
  176. flock/themes/iterm2-dark-background.toml +77 -0
  177. flock/themes/iterm2-default.toml +77 -0
  178. flock/themes/iterm2-light-background.toml +77 -0
  179. flock/themes/iterm2-pastel-dark-background.toml +77 -0
  180. flock/themes/iterm2-smoooooth.toml +77 -0
  181. flock/themes/iterm2-solarized-dark.toml +77 -0
  182. flock/themes/iterm2-solarized-light.toml +77 -0
  183. flock/themes/iterm2-tango-dark.toml +77 -0
  184. flock/themes/iterm2-tango-light.toml +77 -0
  185. flock/themes/jackie-brown.toml +77 -0
  186. flock/themes/japanesque.toml +77 -0
  187. flock/themes/jellybeans.toml +77 -0
  188. flock/themes/jetbrains-darcula.toml +77 -0
  189. flock/themes/jubi.toml +77 -0
  190. flock/themes/kanagawabones.toml +77 -0
  191. flock/themes/kibble.toml +77 -0
  192. flock/themes/kolorit.toml +77 -0
  193. flock/themes/konsolas.toml +77 -0
  194. flock/themes/kurokula.toml +77 -0
  195. flock/themes/lab-fox.toml +77 -0
  196. flock/themes/laser.toml +77 -0
  197. flock/themes/later-this-evening.toml +77 -0
  198. flock/themes/lavandula.toml +77 -0
  199. flock/themes/liquidcarbon.toml +77 -0
  200. flock/themes/liquidcarbontransparent.toml +77 -0
  201. flock/themes/liquidcarbontransparentinverse.toml +77 -0
  202. flock/themes/lovelace.toml +77 -0
  203. flock/themes/man-page.toml +77 -0
  204. flock/themes/mariana.toml +77 -0
  205. flock/themes/material.toml +77 -0
  206. flock/themes/materialdark.toml +77 -0
  207. flock/themes/materialdarker.toml +77 -0
  208. flock/themes/materialdesigncolors.toml +77 -0
  209. flock/themes/materialocean.toml +77 -0
  210. flock/themes/mathias.toml +77 -0
  211. flock/themes/matrix.toml +77 -0
  212. flock/themes/medallion.toml +77 -0
  213. flock/themes/mellifluous.toml +77 -0
  214. flock/themes/midnight-in-mojave.toml +77 -0
  215. flock/themes/mirage.toml +77 -0
  216. flock/themes/misterioso.toml +77 -0
  217. flock/themes/molokai.toml +77 -0
  218. flock/themes/monalisa.toml +77 -0
  219. flock/themes/monokai-remastered.toml +77 -0
  220. flock/themes/monokai-soda.toml +77 -0
  221. flock/themes/monokai-vivid.toml +77 -0
  222. flock/themes/n0tch2k.toml +77 -0
  223. flock/themes/neobones-dark.toml +77 -0
  224. flock/themes/neobones-light.toml +77 -0
  225. flock/themes/neon.toml +77 -0
  226. flock/themes/neopolitan.toml +77 -0
  227. flock/themes/neutron.toml +77 -0
  228. flock/themes/night-owlish-light.toml +77 -0
  229. flock/themes/nightfox.toml +77 -0
  230. flock/themes/nightlion-v1.toml +77 -0
  231. flock/themes/nightlion-v2.toml +77 -0
  232. flock/themes/niji.toml +77 -0
  233. flock/themes/nocturnal-winter.toml +77 -0
  234. flock/themes/nord-light.toml +77 -0
  235. flock/themes/nord.toml +77 -0
  236. flock/themes/novel.toml +77 -0
  237. flock/themes/nvimdark.toml +77 -0
  238. flock/themes/nvimlight.toml +77 -0
  239. flock/themes/obsidian.toml +77 -0
  240. flock/themes/ocean.toml +77 -0
  241. flock/themes/oceanic-next.toml +77 -0
  242. flock/themes/oceanicmaterial.toml +77 -0
  243. flock/themes/ollie.toml +77 -0
  244. flock/themes/onehalfdark.toml +77 -0
  245. flock/themes/onehalflight.toml +77 -0
  246. flock/themes/operator-mono-dark.toml +77 -0
  247. flock/themes/overnight-slumber.toml +77 -0
  248. flock/themes/oxocarbon.toml +77 -0
  249. flock/themes/palenighthc.toml +77 -0
  250. flock/themes/pandora.toml +77 -0
  251. flock/themes/paraiso-dark.toml +77 -0
  252. flock/themes/paulmillr.toml +77 -0
  253. flock/themes/pencildark.toml +77 -0
  254. flock/themes/pencillight.toml +77 -0
  255. flock/themes/peppermint.toml +77 -0
  256. flock/themes/piatto-light.toml +77 -0
  257. flock/themes/pnevma.toml +77 -0
  258. flock/themes/popping-and-locking.toml +77 -0
  259. flock/themes/primary.toml +77 -0
  260. flock/themes/pro-light.toml +77 -0
  261. flock/themes/pro.toml +77 -0
  262. flock/themes/purple-rain.toml +77 -0
  263. flock/themes/purplepeter.toml +77 -0
  264. flock/themes/rapture.toml +77 -0
  265. flock/themes/raycast-dark.toml +77 -0
  266. flock/themes/raycast-light.toml +77 -0
  267. flock/themes/rebecca.toml +77 -0
  268. flock/themes/red-alert.toml +77 -0
  269. flock/themes/red-planet.toml +77 -0
  270. flock/themes/red-sands.toml +77 -0
  271. flock/themes/relaxed.toml +77 -0
  272. flock/themes/retro.toml +77 -0
  273. flock/themes/rippedcasts.toml +77 -0
  274. flock/themes/rose-pine-dawn.toml +77 -0
  275. flock/themes/rose-pine-moon.toml +77 -0
  276. flock/themes/rose-pine.toml +77 -0
  277. flock/themes/rouge-2.toml +77 -0
  278. flock/themes/royal.toml +77 -0
  279. flock/themes/ryuuko.toml +77 -0
  280. flock/themes/sakura.toml +77 -0
  281. flock/themes/scarlet-protocol.toml +77 -0
  282. flock/themes/seafoam-pastel.toml +77 -0
  283. flock/themes/seashells.toml +77 -0
  284. flock/themes/seoulbones-dark.toml +77 -0
  285. flock/themes/seoulbones-light.toml +77 -0
  286. flock/themes/seti.toml +77 -0
  287. flock/themes/shades-of-purple.toml +77 -0
  288. flock/themes/shaman.toml +77 -0
  289. flock/themes/slate.toml +77 -0
  290. flock/themes/sleepyhollow.toml +77 -0
  291. flock/themes/smyck.toml +77 -0
  292. flock/themes/snazzy.toml +77 -0
  293. flock/themes/softserver.toml +77 -0
  294. flock/themes/solarized-darcula.toml +77 -0
  295. flock/themes/solarized-dark---patched.toml +77 -0
  296. flock/themes/solarized-dark-higher-contrast.toml +77 -0
  297. flock/themes/spacedust.toml +77 -0
  298. flock/themes/spacegray-eighties-dull.toml +77 -0
  299. flock/themes/spacegray-eighties.toml +77 -0
  300. flock/themes/spacegray.toml +77 -0
  301. flock/themes/spiderman.toml +77 -0
  302. flock/themes/spring.toml +77 -0
  303. flock/themes/square.toml +77 -0
  304. flock/themes/sublette.toml +77 -0
  305. flock/themes/subliminal.toml +77 -0
  306. flock/themes/sugarplum.toml +77 -0
  307. flock/themes/sundried.toml +77 -0
  308. flock/themes/symfonic.toml +77 -0
  309. flock/themes/synthwave-everything.toml +77 -0
  310. flock/themes/synthwave.toml +77 -0
  311. flock/themes/synthwavealpha.toml +77 -0
  312. flock/themes/tango-adapted.toml +77 -0
  313. flock/themes/tango-half-adapted.toml +77 -0
  314. flock/themes/teerb.toml +77 -0
  315. flock/themes/terafox.toml +77 -0
  316. flock/themes/terminal-basic.toml +77 -0
  317. flock/themes/thayer-bright.toml +77 -0
  318. flock/themes/the-hulk.toml +77 -0
  319. flock/themes/tinacious-design-(dark).toml +77 -0
  320. flock/themes/tinacious-design-(light).toml +77 -0
  321. flock/themes/tokyonight-day.toml +77 -0
  322. flock/themes/tokyonight-storm.toml +77 -0
  323. flock/themes/tokyonight.toml +77 -0
  324. flock/themes/tomorrow-night-blue.toml +77 -0
  325. flock/themes/tomorrow-night-bright.toml +77 -0
  326. flock/themes/tomorrow-night-burns.toml +77 -0
  327. flock/themes/tomorrow-night-eighties.toml +77 -0
  328. flock/themes/tomorrow-night.toml +77 -0
  329. flock/themes/tomorrow.toml +77 -0
  330. flock/themes/toychest.toml +77 -0
  331. flock/themes/treehouse.toml +77 -0
  332. flock/themes/twilight.toml +77 -0
  333. flock/themes/ubuntu.toml +77 -0
  334. flock/themes/ultradark.toml +77 -0
  335. flock/themes/ultraviolent.toml +77 -0
  336. flock/themes/underthesea.toml +77 -0
  337. flock/themes/unikitty.toml +77 -0
  338. flock/themes/urple.toml +77 -0
  339. flock/themes/vaughn.toml +77 -0
  340. flock/themes/vesper.toml +77 -0
  341. flock/themes/vibrantink.toml +77 -0
  342. flock/themes/vimbones.toml +77 -0
  343. flock/themes/violet-dark.toml +77 -0
  344. flock/themes/violet-light.toml +77 -0
  345. flock/themes/warmneon.toml +77 -0
  346. flock/themes/wez.toml +77 -0
  347. flock/themes/whimsy.toml +77 -0
  348. flock/themes/wildcherry.toml +77 -0
  349. flock/themes/wilmersdorf.toml +77 -0
  350. flock/themes/wombat.toml +77 -0
  351. flock/themes/wryan.toml +77 -0
  352. flock/themes/xcodedark.toml +77 -0
  353. flock/themes/xcodedarkhc.toml +77 -0
  354. flock/themes/xcodelight.toml +77 -0
  355. flock/themes/xcodelighthc.toml +77 -0
  356. flock/themes/xcodewwdc.toml +77 -0
  357. flock/themes/zenbones-dark.toml +77 -0
  358. flock/themes/zenbones-light.toml +77 -0
  359. flock/themes/zenbones.toml +77 -0
  360. flock/themes/zenburn.toml +77 -0
  361. flock/themes/zenburned.toml +77 -0
  362. flock/themes/zenwritten-dark.toml +77 -0
  363. flock/themes/zenwritten-light.toml +77 -0
  364. flock/workflow/activities.py +175 -115
  365. flock/workflow/agent_activities.py +24 -26
  366. flock/workflow/temporal_setup.py +38 -37
  367. flock/workflow/workflow.py +58 -53
  368. flock_core-0.2.2.dist-info/METADATA +320 -0
  369. flock_core-0.2.2.dist-info/RECORD +372 -0
  370. {flock_core-0.1.2.dist-info → flock_core-0.2.2.dist-info}/licenses/LICENSE +21 -21
  371. flock/agents/__init__.py +0 -3
  372. flock/agents/batch_agent.py +0 -175
  373. flock/agents/declarative_agent.py +0 -166
  374. flock/agents/loop_agent.py +0 -178
  375. flock/agents/trigger_agent.py +0 -191
  376. flock/agents/user_agent.py +0 -230
  377. flock/app/components/__init__.py +0 -14
  378. flock/app/components/charts/agent_workflow.py +0 -14
  379. flock/app/components/charts/core_architecture.py +0 -14
  380. flock/app/components/charts/tool_system.py +0 -14
  381. flock/app/components/history_grid.py +0 -168
  382. flock/app/components/history_grid_alt.py +0 -189
  383. flock/app/components/sidebar.py +0 -19
  384. flock/app/components/theme.py +0 -9
  385. flock/app/components/util.py +0 -18
  386. flock/app/hive_app.py +0 -118
  387. flock/app/html/d3.html +0 -179
  388. flock/app/modules/__init__.py +0 -12
  389. flock/app/modules/about.py +0 -17
  390. flock/app/modules/agent_detail.py +0 -70
  391. flock/app/modules/agent_list.py +0 -59
  392. flock/app/modules/playground.py +0 -322
  393. flock/app/modules/settings.py +0 -96
  394. flock/core/agent.py +0 -150
  395. flock/core/agent_registry.py +0 -162
  396. flock/core/context.py +0 -279
  397. flock/core/handoff/handoff_base.py +0 -12
  398. flock/core/logging/error_handler.py +0 -84
  399. flock/core/logging/formatters.py +0 -122
  400. flock/core/logging/handlers.py +0 -117
  401. flock/core/logging/logger.py +0 -107
  402. flock/core/serializable.py +0 -206
  403. flock_core-0.1.2.dist-info/METADATA +0 -476
  404. flock_core-0.1.2.dist-info/RECORD +0 -48
  405. flock_core-0.1.2.dist-info/entry_points.txt +0 -2
  406. /flock/{core/config/declarative_agent_config.py → workflow/__init__.py} +0 -0
  407. {flock_core-0.1.2.dist-info → flock_core-0.2.2.dist-info}/WHEEL +0 -0
@@ -1,230 +0,0 @@
1
- from collections.abc import Callable
2
- from typing import Any
3
-
4
- from pydantic import Field
5
- from temporalio import activity
6
-
7
- from flock.core.agent import Agent
8
- from flock.core.context import FlockContext
9
- from flock.core.logging import flock_logger, live_update_handler, performance_handler
10
-
11
-
12
- @activity.defn
13
- async def run_user_agent_activity(context: dict[str, Any]) -> dict[str, Any]:
14
- """Temporal activity to process a user agent task.
15
-
16
- Expects context to contain:
17
- - "model": the model name
18
- - "agent_input": the key used for the input
19
- - "output": the agent output specification
20
- - "init_input": the initial input
21
- - "tools": (optional) list of tools
22
- """
23
- try:
24
- import dspy
25
-
26
- flock_logger.info("Starting user agent activity", context=context)
27
-
28
- with performance_handler.track_time("model_configuration"):
29
- model = context.get("model")
30
- agent_input = context.get("agent_input")
31
- output = context.get("output")
32
- init_input = context.get("init_input")
33
- tools = context.get("tools")
34
-
35
- flock_logger.debug(
36
- "Configuring model",
37
- model=model,
38
- input=agent_input,
39
- output=output,
40
- )
41
-
42
- lm = dspy.LM(model)
43
- dspy.configure(lm=lm)
44
-
45
- with performance_handler.track_time("task_execution"):
46
- if tools:
47
- flock_logger.info("Creating ReAct task with tools", num_tools=len(tools))
48
- agent_task = dspy.ReAct(f"{agent_input} -> {output}", tools=tools)
49
- else:
50
- flock_logger.info("Creating Predict task")
51
- agent_task = dspy.Predict(f"{agent_input} -> {output}")
52
-
53
- kwargs = {agent_input: init_input}
54
- flock_logger.info("Executing task", kwargs=kwargs)
55
- result = agent_task(**kwargs).toDict()
56
- result[agent_input] = init_input
57
-
58
- flock_logger.success("Task completed successfully")
59
- return result
60
-
61
- except Exception as e:
62
- flock_logger.error(
63
- "User agent activity failed",
64
- error=str(e),
65
- context=context,
66
- )
67
- raise
68
-
69
-
70
- class UserAgent(Agent):
71
- """An agent that evaluates declarative inputs with user interaction capabilities.
72
-
73
- This agent extends the base Agent class with the ability to interact with users
74
- during execution, while maintaining compatibility with both local and Temporal
75
- execution modes.
76
-
77
- Attributes:
78
- input: Input domain for the agent
79
- output: Output types for the agent
80
- tools: Tools the agent is allowed to use
81
- require_confirmation: Whether to require user confirmation before proceeding
82
- """
83
-
84
- input: str = Field(default="", description="Input domain for the agent")
85
- output: str = Field(default="", description="Output types for the agent")
86
- tools: list[Callable] | None = Field(default=None, description="Tools the agent is allowed to use")
87
- require_confirmation: bool = Field(default=False, description="Whether to require user confirmation")
88
-
89
- async def _configure_model(self) -> tuple[Any, Any]:
90
- """Configure the model and create the appropriate task."""
91
- try:
92
- with performance_handler.track_time("model_configuration"):
93
- import dspy
94
-
95
- flock_logger.debug(
96
- "Configuring model",
97
- model=self.model,
98
- input=self.input,
99
- output=self.output,
100
- )
101
-
102
- lm = dspy.LM(self.model)
103
- dspy.configure(lm=lm)
104
-
105
- if self.tools:
106
- flock_logger.info("Creating ReAct task with tools", num_tools=len(self.tools))
107
- agent_task = dspy.ReAct(f"{self.input} -> {self.output}", tools=self.tools)
108
- else:
109
- flock_logger.info("Creating Predict task")
110
- agent_task = dspy.Predict(f"{self.input} -> {self.output}")
111
-
112
- return lm, agent_task
113
-
114
- except Exception as e:
115
- flock_logger.error(
116
- "Model configuration failed",
117
- error=str(e),
118
- agent=self.name,
119
- )
120
- raise
121
-
122
- async def _execute_task(self, task: Any, context: FlockContext) -> dict[str, Any]:
123
- """Execute the configured task."""
124
- try:
125
- with performance_handler.track_time("task_execution"):
126
- kwargs = {self.input: context.get_variable("init_input")}
127
- flock_logger.info("Executing task", kwargs=kwargs)
128
-
129
- with live_update_handler.update_activity_status(
130
- self.name,
131
- "Executing Task",
132
- "Running",
133
- {"input": kwargs},
134
- ):
135
- result = task(**kwargs).toDict()
136
- result[self.input] = kwargs[self.input]
137
-
138
- flock_logger.success("Task executed successfully")
139
- return result
140
-
141
- except Exception as e:
142
- flock_logger.error(
143
- "Task execution failed",
144
- error=str(e),
145
- agent=self.name,
146
- kwargs=kwargs,
147
- )
148
- raise
149
-
150
- async def run(self, context: FlockContext) -> dict[str, Any]:
151
- """Run the agent on a task with optional user interaction."""
152
- try:
153
- flock_logger.info(f"Starting user agent: {self.name}")
154
-
155
- # Configure model and task
156
- _, task = await self._configure_model()
157
-
158
- # Execute with user confirmation if required
159
- if self.require_confirmation:
160
- with live_update_handler.update_activity_status(
161
- self.name,
162
- "Awaiting User Confirmation",
163
- "Paused",
164
- {"agent": self.name},
165
- ):
166
- flock_logger.info("Waiting for user confirmation")
167
- # Here you would implement user confirmation logic
168
- # For now, we'll just proceed
169
- pass
170
-
171
- # Execute the task
172
- result = await self._execute_task(task, context)
173
- return result
174
-
175
- except Exception as e:
176
- flock_logger.error(
177
- "User agent execution failed",
178
- error=str(e),
179
- agent=self.name,
180
- )
181
- raise
182
-
183
- async def run_temporal(self, context: FlockContext) -> dict[str, Any]:
184
- """Run the user agent via Temporal."""
185
- try:
186
- from temporalio.client import Client
187
-
188
- from flock.workflow.temporal_setup import run_activity
189
-
190
- with performance_handler.track_time("temporal_setup"):
191
- flock_logger.info(f"Starting temporal user agent: {self.name}")
192
- client = await Client.connect("localhost:7233", namespace="default")
193
-
194
- # Prepare context for temporal activity
195
- activity_context = {
196
- "model": self.model,
197
- "agent_input": self.input,
198
- "output": self.output,
199
- "init_input": context.get_variable("init_input"),
200
- "tools": self.tools,
201
- }
202
-
203
- with live_update_handler.update_workflow_status(
204
- self.name,
205
- "Running",
206
- {"phase": "user_agent_execution"},
207
- ):
208
- # Execute the activity
209
- with performance_handler.track_time("temporal_execution"):
210
- flock_logger.info("Starting user agent activity")
211
- result = await run_activity(
212
- client,
213
- self.name,
214
- run_user_agent_activity,
215
- activity_context,
216
- )
217
-
218
- flock_logger.success(
219
- "Temporal user agent completed successfully",
220
- agent=self.name,
221
- )
222
- return result
223
-
224
- except Exception as e:
225
- flock_logger.error(
226
- "Temporal user agent execution failed",
227
- error=str(e),
228
- agent=self.name,
229
- )
230
- raise
@@ -1,14 +0,0 @@
1
- from .charts.agent_workflow import AgentWorkflowChart
2
- from .charts.core_architecture import CoreArchitectureChart
3
- from .history_grid import HistoryGrid
4
- from .sidebar import Sidebar
5
- from .theme import Theme, ThemeDialog
6
-
7
- __all__ = [
8
- "AgentWorkflowChart",
9
- "CoreArchitectureChart",
10
- "HistoryGrid",
11
- "Sidebar",
12
- "Theme",
13
- "ThemeDialog",
14
- ]
@@ -1,14 +0,0 @@
1
- from fasthtml.common import *
2
- from fasthtml.svg import *
3
- from monsterui.all import *
4
-
5
-
6
- def AgentWorkflowChart():
7
- return Div(
8
- Div(
9
- style="max-width:100%;border:1px solid transparent;",
10
- data_mxgraph='{"highlight":"#0000ff","nav":true,"resize":true,"page":1,"toolbar":"pages zoom layers tags lightbox","edit":"_blank","xml":"<mxfile><diagram id=\\"l7_B5a2V6sOU66k4eApJ\\" name=\\"Core Architecture\\"><mxGraphModel dx=\\"1139\\" dy=\\"934\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#FFFFFF\\" math=\\"0\\" shadow=\\"1\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"3\\" value=\\"graph TB&#10; subgraph User Application&#10; UA[User Code] --&gt; |Uses| SM[Flock Manager]&#10; end&#10;&#10; subgraph Flock Core&#10; SM --&gt; |Manages| AR[Agent Registry]&#10; SM --&gt; |Executes| WF[Workflow System]&#10; &#10; subgraph Agents&#10; AR --&gt; |Registers| DA[Declarative Agent]&#10; DA --&gt; |Uses| TS[Type System]&#10; DA --&gt; |Uses| TM[Tool Manager]&#10; end&#10; &#10; subgraph Workflow&#10; WF --&gt; |Runs| AC[Activities]&#10; WF --&gt; |Uses| TW[Temporal Worker]&#10; AC --&gt; |Executes| DA&#10; end&#10; end&#10;&#10; subgraph External Systems&#10; TW --&gt; |Connects to| TS1[Temporal Server]&#10; TM --&gt; |Integrates| T1[Web Search]&#10; TM --&gt; |Integrates| T2[Code Eval]&#10; TM --&gt; |Integrates| T3[Math Tools]&#10; DA --&gt; |Uses| LLM[LLM Provider]&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef external fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef user fill:#bfb,stroke:#333,stroke-width:2px&#10; &#10; class SM,AR,DA,WF,AC,TM,TS core&#10; class TS1,T1,T2,T3,LLM external&#10; class UA user&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;rounded=1;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"200\\" y=\\"310\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"m33Os__FMXyp1zJ4IDTH\\" name=\\"Agent Workflow\\"><mxGraphModel dx=\\"1139\\" dy=\\"934\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"Yf0mmGmI6B4_u023lZ5C-1\\" value=\\"sequenceDiagram&#10; participant User&#10; participant Flock&#10; participant Agent&#10; participant Tools&#10; participant LLM&#10; participant Temporal&#10;&#10; User-&gt;&gt;Flock: Create Agent&#10; Flock-&gt;&gt;Agent: Initialize&#10; User-&gt;&gt;Flock: activate(agent, input)&#10; &#10; alt Local Debug Mode&#10; Flock-&gt;&gt;Agent: Execute Directly&#10; else Production Mode&#10; Flock-&gt;&gt;Temporal: Start Workflow&#10; Temporal-&gt;&gt;Agent: Execute via Activity&#10; end&#10;&#10; loop Agent Execution&#10; Agent-&gt;&gt;LLM: Process Input&#10; opt Tool Usage&#10; Agent-&gt;&gt;Tools: Execute Tool&#10; Tools--&gt;&gt;Agent: Tool Result&#10; end&#10; Agent-&gt;&gt;LLM: Generate Output&#10; end&#10;&#10; alt Has Hand-off&#10; Agent-&gt;&gt;Flock: Hand off to Next Agent&#10; Flock-&gt;&gt;Agent: Start Next Agent&#10; else No Hand-off&#10; Agent--&gt;&gt;Flock: Return Result&#10; end&#10;&#10; Flock--&gt;&gt;User: Return Final Result\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"275\\" y=\\"114\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"zsmzvY-bLYlccnSXdfzv\\" name=\\"Temporal Workflow\\">\\n <mxGraphModel dx=\\"205\\" dy=\\"165\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\">\\n <root>\\n <mxCell id=\\"0\\"/>\\n <mxCell id=\\"1\\" parent=\\"0\\"/>\\n <mxCell id=\\"LGo0nXY-PDX6Si-UCiUW-1\\" value=\\"graph TB&#10; subgraph Temporal Integration&#10; WF[Workflow System] --&gt; |Manages| TW[Temporal Worker]&#10; TW --&gt; |Executes| AC[Activities]&#10; TW --&gt; |Connects to| TS[Temporal Server]&#10; &#10; subgraph State Management&#10; TS --&gt; |Manages| WS[Workflow State]&#10; WS --&gt; |Tracks| AS[Agent State]&#10; WS --&gt; |Tracks| TS1[Tool State]&#10; WS --&gt; |Tracks| ES[Error State]&#10; end&#10;&#10; subgraph Reliability Features&#10; TS --&gt; |Provides| R1[Automatic Retries]&#10; TS --&gt; |Provides| R2[Error Recovery]&#10; TS --&gt; |Provides| R3[State Persistence]&#10; TS --&gt; |Provides| R4[Workflow History]&#10; end&#10;&#10; subgraph Monitoring&#10; TS --&gt; |Enables| M1[Execution Metrics]&#10; TS --&gt; |Enables| M2[Error Tracking]&#10; TS --&gt; |Enables| M3[Performance Stats]&#10; TS --&gt; |Enables| M4[Workflow Visualization]&#10; end&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef state fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef feature fill:#bfb,stroke:#333,stroke-width:2px&#10; classDef monitor fill:#fbb,stroke:#333,stroke-width:2px&#10;&#10; class WF,TW,AC,TS core&#10; class WS,AS,TS1,ES state&#10; class R1,R2,R3,R4 feature&#10; class M1,M2,M3,M4 monitor&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"242\\" y=\\"169\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/>\\n </mxCell>\\n </root>\\n </mxGraphModel>\\n </diagram><diagram id=\\"FU8wRJNSLGF58lYnAYQQ\\" name=\\"Tool System\\">\\n <mxGraphModel dx=\\"307\\" dy=\\"248\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\">\\n <root>\\n <mxCell id=\\"0\\"/>\\n <mxCell id=\\"1\\" parent=\\"0\\"/>\\n <mxCell id=\\"T-pgXY2fyKOihok5m5tA-1\\" value=\\"graph TB&#10; subgraph Tool Management&#10; TM[Tool Manager] --&gt; |Manages| TR[Tool Registry]&#10; TR --&gt; |Registers| T1[Web Search Tool]&#10; TR --&gt; |Registers| T2[Code Eval Tool]&#10; TR --&gt; |Registers| T3[Math Tool]&#10; &#10; TM --&gt; |Provides| TI[Tool Interface]&#10; TI --&gt; |Used by| DA[Declarative Agent]&#10; end&#10;&#10; subgraph Tool Execution&#10; T1 --&gt; |Uses| WS[Web Search API]&#10; T2 --&gt; |Uses| CE[Code Executor]&#10; T3 --&gt; |Uses| ME[Math Engine]&#10; &#10; WS --&gt; |Returns| R1[Search Results]&#10; CE --&gt; |Returns| R2[Execution Results]&#10; ME --&gt; |Returns| R3[Math Results]&#10; end&#10;&#10; subgraph Error Handling&#10; TM --&gt; |Manages| EH[Error Handler]&#10; EH --&gt; |Handles| E1[API Errors]&#10; EH --&gt; |Handles| E2[Execution Errors]&#10; EH --&gt; |Handles| E3[Validation Errors]&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef tool fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef handler fill:#bfb,stroke:#333,stroke-width:2px&#10;&#10; class TM,TR,TI core&#10; class T1,T2,T3,WS,CE,ME tool&#10; class EH,E1,E2,E3 handler\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"240\\" y=\\"170\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/>\\n </mxCell>\\n </root>\\n </mxGraphModel>\\n </diagram><diagram id=\\"44PLLl0pgulDx2n2xTWC\\" name=\\"Type System\\">\\n <mxGraphModel dx=\\"767\\" dy=\\"620\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\">\\n <root>\\n <mxCell id=\\"0\\"/>\\n <mxCell id=\\"1\\" parent=\\"0\\"/>\\n <mxCell id=\\"jTONh3Pudjw2xIwc2DDu-1\\" value=\\"classDiagram&#10; class TypeSystem {&#10; +register_type(name, validator, serializer)&#10; +validate(value, type_def)&#10; +parse_type_string(type_str)&#10; -_validate_complex_type(value, type_def)&#10; }&#10;&#10; class TypeDefinition {&#10; +name: str&#10; +validators: List&#10; +serializers: Optional&#10; +validate(value)&#10; +serialize(value)&#10; }&#10;&#10; class DeclarativeAgent {&#10; +input: str&#10; +output: str&#10; +tools: List&#10; +validate_input(value)&#10; +validate_output(value)&#10; }&#10;&#10; class Validator {&#10; +validate(value)&#10; +coerce(value)&#10; }&#10;&#10; TypeSystem --&gt; TypeDefinition : manages&#10; DeclarativeAgent --&gt; TypeSystem : uses&#10; TypeDefinition --&gt; Validator : uses&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"242\\" y=\\"169\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/>\\n </mxCell>\\n </root>\\n </mxGraphModel>\\n </diagram></mxfile>"}',
11
- cls="mxgraph",
12
- ),
13
- Script(type="text/javascript", src="https://viewer.diagrams.net/js/viewer-static.min.js"),
14
- )
@@ -1,14 +0,0 @@
1
- from fasthtml.common import *
2
- from fasthtml.svg import *
3
- from monsterui.all import *
4
-
5
-
6
- def CoreArchitectureChart():
7
- return Div(
8
- Div(
9
- style="max-width:100%;border:1px solid transparent;",
10
- data_mxgraph='{"highlight":"#0000ff","nav":true,"resize":true,"page":0,"toolbar":"pages zoom layers tags lightbox","edit":"_blank","xml":"<mxfile><diagram id=\\"l7_B5a2V6sOU66k4eApJ\\" name=\\"Core Architecture\\"><mxGraphModel dx=\\"1139\\" dy=\\"934\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#FFFFFF\\" math=\\"0\\" shadow=\\"1\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"3\\" value=\\"graph TB&#10; subgraph User Application&#10; UA[User Code] --&gt; |Uses| SM[Flock Manager]&#10; end&#10;&#10; subgraph Flock Core&#10; SM --&gt; |Manages| AR[Agent Registry]&#10; SM --&gt; |Executes| WF[Workflow System]&#10; &#10; subgraph Agents&#10; AR --&gt; |Registers| DA[Declarative Agent]&#10; DA --&gt; |Uses| TS[Type System]&#10; DA --&gt; |Uses| TM[Tool Manager]&#10; end&#10; &#10; subgraph Workflow&#10; WF --&gt; |Runs| AC[Activities]&#10; WF --&gt; |Uses| TW[Temporal Worker]&#10; AC --&gt; |Executes| DA&#10; end&#10; end&#10;&#10; subgraph External Systems&#10; TW --&gt; |Connects to| TS1[Temporal Server]&#10; TM --&gt; |Integrates| T1[Web Search]&#10; TM --&gt; |Integrates| T2[Code Eval]&#10; TM --&gt; |Integrates| T3[Math Tools]&#10; DA --&gt; |Uses| LLM[LLM Provider]&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef external fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef user fill:#bfb,stroke:#333,stroke-width:2px&#10; &#10; class SM,AR,DA,WF,AC,TM,TS core&#10; class TS1,T1,T2,T3,LLM external&#10; class UA user&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;rounded=1;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"200\\" y=\\"310\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"m33Os__FMXyp1zJ4IDTH\\" name=\\"Agent Workflow\\"><mxGraphModel dx=\\"1139\\" dy=\\"934\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"Yf0mmGmI6B4_u023lZ5C-1\\" value=\\"sequenceDiagram&#10; participant User&#10; participant Flock&#10; participant Agent&#10; participant Tools&#10; participant LLM&#10; participant Temporal&#10;&#10; User-&gt;&gt;Flock: Create Agent&#10; Flock-&gt;&gt;Agent: Initialize&#10; User-&gt;&gt;Flock: activate(agent, input)&#10; &#10; alt Local Debug Mode&#10; Flock-&gt;&gt;Agent: Execute Directly&#10; else Production Mode&#10; Flock-&gt;&gt;Temporal: Start Workflow&#10; Temporal-&gt;&gt;Agent: Execute via Activity&#10; end&#10;&#10; loop Agent Execution&#10; Agent-&gt;&gt;LLM: Process Input&#10; opt Tool Usage&#10; Agent-&gt;&gt;Tools: Execute Tool&#10; Tools--&gt;&gt;Agent: Tool Result&#10; end&#10; Agent-&gt;&gt;LLM: Generate Output&#10; end&#10;&#10; alt Has Hand-off&#10; Agent-&gt;&gt;Flock: Hand off to Next Agent&#10; Flock-&gt;&gt;Agent: Start Next Agent&#10; else No Hand-off&#10; Agent--&gt;&gt;Flock: Return Result&#10; end&#10;&#10; Flock--&gt;&gt;User: Return Final Result\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"275\\" y=\\"114\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"zsmzvY-bLYlccnSXdfzv\\" name=\\"Temporal Workflow\\">\\n <mxGraphModel dx=\\"205\\" dy=\\"165\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\">\\n <root>\\n <mxCell id=\\"0\\"/>\\n <mxCell id=\\"1\\" parent=\\"0\\"/>\\n <mxCell id=\\"LGo0nXY-PDX6Si-UCiUW-1\\" value=\\"graph TB&#10; subgraph Temporal Integration&#10; WF[Workflow System] --&gt; |Manages| TW[Temporal Worker]&#10; TW --&gt; |Executes| AC[Activities]&#10; TW --&gt; |Connects to| TS[Temporal Server]&#10; &#10; subgraph State Management&#10; TS --&gt; |Manages| WS[Workflow State]&#10; WS --&gt; |Tracks| AS[Agent State]&#10; WS --&gt; |Tracks| TS1[Tool State]&#10; WS --&gt; |Tracks| ES[Error State]&#10; end&#10;&#10; subgraph Reliability Features&#10; TS --&gt; |Provides| R1[Automatic Retries]&#10; TS --&gt; |Provides| R2[Error Recovery]&#10; TS --&gt; |Provides| R3[State Persistence]&#10; TS --&gt; |Provides| R4[Workflow History]&#10; end&#10;&#10; subgraph Monitoring&#10; TS --&gt; |Enables| M1[Execution Metrics]&#10; TS --&gt; |Enables| M2[Error Tracking]&#10; TS --&gt; |Enables| M3[Performance Stats]&#10; TS --&gt; |Enables| M4[Workflow Visualization]&#10; end&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef state fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef feature fill:#bfb,stroke:#333,stroke-width:2px&#10; classDef monitor fill:#fbb,stroke:#333,stroke-width:2px&#10;&#10; class WF,TW,AC,TS core&#10; class WS,AS,TS1,ES state&#10; class R1,R2,R3,R4 feature&#10; class M1,M2,M3,M4 monitor&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"242\\" y=\\"169\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/>\\n </mxCell>\\n </root>\\n </mxGraphModel>\\n </diagram><diagram id=\\"FU8wRJNSLGF58lYnAYQQ\\" name=\\"Tool System\\">\\n <mxGraphModel dx=\\"307\\" dy=\\"248\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\">\\n <root>\\n <mxCell id=\\"0\\"/>\\n <mxCell id=\\"1\\" parent=\\"0\\"/>\\n <mxCell id=\\"T-pgXY2fyKOihok5m5tA-1\\" value=\\"graph TB&#10; subgraph Tool Management&#10; TM[Tool Manager] --&gt; |Manages| TR[Tool Registry]&#10; TR --&gt; |Registers| T1[Web Search Tool]&#10; TR --&gt; |Registers| T2[Code Eval Tool]&#10; TR --&gt; |Registers| T3[Math Tool]&#10; &#10; TM --&gt; |Provides| TI[Tool Interface]&#10; TI --&gt; |Used by| DA[Declarative Agent]&#10; end&#10;&#10; subgraph Tool Execution&#10; T1 --&gt; |Uses| WS[Web Search API]&#10; T2 --&gt; |Uses| CE[Code Executor]&#10; T3 --&gt; |Uses| ME[Math Engine]&#10; &#10; WS --&gt; |Returns| R1[Search Results]&#10; CE --&gt; |Returns| R2[Execution Results]&#10; ME --&gt; |Returns| R3[Math Results]&#10; end&#10;&#10; subgraph Error Handling&#10; TM --&gt; |Manages| EH[Error Handler]&#10; EH --&gt; |Handles| E1[API Errors]&#10; EH --&gt; |Handles| E2[Execution Errors]&#10; EH --&gt; |Handles| E3[Validation Errors]&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef tool fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef handler fill:#bfb,stroke:#333,stroke-width:2px&#10;&#10; class TM,TR,TI core&#10; class T1,T2,T3,WS,CE,ME tool&#10; class EH,E1,E2,E3 handler\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"240\\" y=\\"170\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/>\\n </mxCell>\\n </root>\\n </mxGraphModel>\\n </diagram><diagram id=\\"44PLLl0pgulDx2n2xTWC\\" name=\\"Type System\\">\\n <mxGraphModel dx=\\"767\\" dy=\\"620\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\">\\n <root>\\n <mxCell id=\\"0\\"/>\\n <mxCell id=\\"1\\" parent=\\"0\\"/>\\n <mxCell id=\\"jTONh3Pudjw2xIwc2DDu-1\\" value=\\"classDiagram&#10; class TypeSystem {&#10; +register_type(name, validator, serializer)&#10; +validate(value, type_def)&#10; +parse_type_string(type_str)&#10; -_validate_complex_type(value, type_def)&#10; }&#10;&#10; class TypeDefinition {&#10; +name: str&#10; +validators: List&#10; +serializers: Optional&#10; +validate(value)&#10; +serialize(value)&#10; }&#10;&#10; class DeclarativeAgent {&#10; +input: str&#10; +output: str&#10; +tools: List&#10; +validate_input(value)&#10; +validate_output(value)&#10; }&#10;&#10; class Validator {&#10; +validate(value)&#10; +coerce(value)&#10; }&#10;&#10; TypeSystem --&gt; TypeDefinition : manages&#10; DeclarativeAgent --&gt; TypeSystem : uses&#10; TypeDefinition --&gt; Validator : uses&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"242\\" y=\\"169\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/>\\n </mxCell>\\n </root>\\n </mxGraphModel>\\n </diagram></mxfile>"}',
11
- cls="mxgraph",
12
- ),
13
- Script(type="text/javascript", src="https://viewer.diagrams.net/js/viewer-static.min.js"),
14
- )
@@ -1,14 +0,0 @@
1
- from fasthtml.common import *
2
- from fasthtml.svg import *
3
- from monsterui.all import *
4
-
5
-
6
- def ToolSystemChart():
7
- return Div(
8
- Div(
9
- style="max-width:100%;border:1px solid transparent;",
10
- data_mxgraph='{"highlight":"#0000ff","nav":true,"resize":true,"page":3,"toolbar":"pages zoom layers tags lightbox","edit":"_blank","xml":"<mxfile><diagram id=\\"l7_B5a2V6sOU66k4eApJ\\" name=\\"Core Architecture\\"><mxGraphModel dx=\\"380\\" dy=\\"311\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#FFFFFF\\" math=\\"0\\" shadow=\\"0\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"3\\" value=\\"graph TB&#10; subgraph User Application&#10; UA[User Code] --&gt; |Uses| SM[Flock Manager]&#10; end&#10;&#10; subgraph Flock Core&#10; SM --&gt; |Manages| AR[Agent Registry]&#10; SM --&gt; |Executes| WF[Workflow System]&#10; &#10; subgraph Agents&#10; AR --&gt; |Registers| DA[Declarative Agent]&#10; DA --&gt; |Uses| TS[Type System]&#10; DA --&gt; |Uses| TM[Tool Manager]&#10; end&#10; &#10; subgraph Workflow&#10; WF --&gt; |Runs| AC[Activities]&#10; WF --&gt; |Uses| TW[Temporal Worker]&#10; AC --&gt; |Executes| DA&#10; end&#10; end&#10;&#10; subgraph External Systems&#10; TW --&gt; |Connects to| TS1[Temporal Server]&#10; TM --&gt; |Integrates| T1[Web Search]&#10; TM --&gt; |Integrates| T2[Code Eval]&#10; TM --&gt; |Integrates| T3[Math Tools]&#10; DA --&gt; |Uses| LLM[LLM Provider]&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef external fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef user fill:#bfb,stroke:#333,stroke-width:2px&#10; &#10; class SM,AR,DA,WF,AC,TM,TS core&#10; class TS1,T1,T2,T3,LLM external&#10; class UA user&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;rounded=1;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"200\\" y=\\"310\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"m33Os__FMXyp1zJ4IDTH\\" name=\\"Agent Workflow\\"><mxGraphModel dx=\\"316\\" dy=\\"259\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"0\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"Yf0mmGmI6B4_u023lZ5C-1\\" value=\\"sequenceDiagram&#10; participant User&#10; participant Flock&#10; participant Agent&#10; participant Tools&#10; participant LLM&#10; participant Temporal&#10;&#10; User-&gt;&gt;Flock: Create Agent&#10; Flock-&gt;&gt;Agent: Initialize&#10; User-&gt;&gt;Flock: activate(agent, input)&#10; &#10; alt Local Debug Mode&#10; Flock-&gt;&gt;Agent: Execute Directly&#10; else Production Mode&#10; Flock-&gt;&gt;Temporal: Start Workflow&#10; Temporal-&gt;&gt;Agent: Execute via Activity&#10; end&#10;&#10; loop Agent Execution&#10; Agent-&gt;&gt;LLM: Process Input&#10; opt Tool Usage&#10; Agent-&gt;&gt;Tools: Execute Tool&#10; Tools--&gt;&gt;Agent: Tool Result&#10; end&#10; Agent-&gt;&gt;LLM: Generate Output&#10; end&#10;&#10; alt Has Hand-off&#10; Agent-&gt;&gt;Flock: Hand off to Next Agent&#10; Flock-&gt;&gt;Agent: Start Next Agent&#10; else No Hand-off&#10; Agent--&gt;&gt;Flock: Return Result&#10; end&#10;&#10; Flock--&gt;&gt;User: Return Final Result\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"275\\" y=\\"114\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"zsmzvY-bLYlccnSXdfzv\\" name=\\"Temporal Workflow\\"><mxGraphModel dx=\\"1139\\" dy=\\"934\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"LGo0nXY-PDX6Si-UCiUW-1\\" value=\\"graph TB&#10; subgraph Temporal Integration&#10; WF[Workflow System] --&gt; |Manages| TW[Temporal Worker]&#10; TW --&gt; |Executes| AC[Activities]&#10; TW --&gt; |Connects to| TS[Temporal Server]&#10; &#10; subgraph State Management&#10; TS --&gt; |Manages| WS[Workflow State]&#10; WS --&gt; |Tracks| AS[Agent State]&#10; WS --&gt; |Tracks| TS1[Tool State]&#10; WS --&gt; |Tracks| ES[Error State]&#10; end&#10;&#10; subgraph Reliability Features&#10; TS --&gt; |Provides| R1[Automatic Retries]&#10; TS --&gt; |Provides| R2[Error Recovery]&#10; TS --&gt; |Provides| R3[State Persistence]&#10; TS --&gt; |Provides| R4[Workflow History]&#10; end&#10;&#10; subgraph Monitoring&#10; TS --&gt; |Enables| M1[Execution Metrics]&#10; TS --&gt; |Enables| M2[Error Tracking]&#10; TS --&gt; |Enables| M3[Performance Stats]&#10; TS --&gt; |Enables| M4[Workflow Visualization]&#10; end&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef state fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef feature fill:#bfb,stroke:#333,stroke-width:2px&#10; classDef monitor fill:#fbb,stroke:#333,stroke-width:2px&#10;&#10; class WF,TW,AC,TS core&#10; class WS,AS,TS1,ES state&#10; class R1,R2,R3,R4 feature&#10; class M1,M2,M3,M4 monitor&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"242\\" y=\\"169\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"FU8wRJNSLGF58lYnAYQQ\\" name=\\"Tool System\\"><mxGraphModel dx=\\"316\\" dy=\\"259\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"0\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"T-pgXY2fyKOihok5m5tA-1\\" value=\\"graph TB&#10; subgraph Tool Management&#10; TM[Tool Manager] --&gt; |Manages| TR[Tool Registry]&#10; TR --&gt; |Registers| T1[Web Search Tool]&#10; TR --&gt; |Registers| T2[Code Eval Tool]&#10; TR --&gt; |Registers| T3[Math Tool]&#10; &#10; TM --&gt; |Provides| TI[Tool Interface]&#10; TI --&gt; |Used by| DA[Declarative Agent]&#10; end&#10;&#10; subgraph Tool Execution&#10; T1 --&gt; |Uses| WS[Web Search API]&#10; T2 --&gt; |Uses| CE[Code Executor]&#10; T3 --&gt; |Uses| ME[Math Engine]&#10; &#10; WS --&gt; |Returns| R1[Search Results]&#10; CE --&gt; |Returns| R2[Execution Results]&#10; ME --&gt; |Returns| R3[Math Results]&#10; end&#10;&#10; subgraph Error Handling&#10; TM --&gt; |Manages| EH[Error Handler]&#10; EH --&gt; |Handles| E1[API Errors]&#10; EH --&gt; |Handles| E2[Execution Errors]&#10; EH --&gt; |Handles| E3[Validation Errors]&#10; end&#10;&#10; classDef core fill:#f9f,stroke:#333,stroke-width:2px&#10; classDef tool fill:#bbf,stroke:#333,stroke-width:2px&#10; classDef handler fill:#bfb,stroke:#333,stroke-width:2px&#10;&#10; class TM,TR,TI core&#10; class T1,T2,T3,WS,CE,ME tool&#10; class EH,E1,E2,E3 handler\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"224\\" y=\\"232\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram><diagram id=\\"44PLLl0pgulDx2n2xTWC\\" name=\\"Type System\\"><mxGraphModel dx=\\"380\\" dy=\\"311\\" grid=\\"0\\" gridSize=\\"10\\" guides=\\"1\\" tooltips=\\"1\\" connect=\\"1\\" arrows=\\"1\\" fold=\\"1\\" page=\\"1\\" pageScale=\\"1\\" pageWidth=\\"850\\" pageHeight=\\"1100\\" background=\\"#ffffff\\" math=\\"0\\" shadow=\\"1\\"><root><mxCell id=\\"0\\"/><mxCell id=\\"1\\" parent=\\"0\\"/><mxCell id=\\"jTONh3Pudjw2xIwc2DDu-1\\" value=\\"classDiagram&#10; class TypeSystem {&#10; +register_type(name, validator, serializer)&#10; +validate(value, type_def)&#10; +parse_type_string(type_str)&#10; -_validate_complex_type(value, type_def)&#10; }&#10;&#10; class TypeDefinition {&#10; +name: str&#10; +validators: List&#10; +serializers: Optional&#10; +validate(value)&#10; +serialize(value)&#10; }&#10;&#10; class DeclarativeAgent {&#10; +input: str&#10; +output: str&#10; +tools: List&#10; +validate_input(value)&#10; +validate_output(value)&#10; }&#10;&#10; class Validator {&#10; +validate(value)&#10; +coerce(value)&#10; }&#10;&#10; TypeSystem --&gt; TypeDefinition : manages&#10; DeclarativeAgent --&gt; TypeSystem : uses&#10; TypeDefinition --&gt; Validator : uses&#10;&#10;\\" style=\\"shadow=0;dashed=0;align=left;strokeWidth=1;shape=mxgraph.mermaid.abstract.mermaid;labelBackgroundColor=#ffffff;noLabel=1;theme=default;\\" parent=\\"1\\" vertex=\\"1\\"><mxGeometry x=\\"242\\" y=\\"169\\" width=\\"300\\" height=\\"300\\" as=\\"geometry\\"/></mxCell></root></mxGraphModel></diagram></mxfile>"}',
11
- cls="mxgraph",
12
- ),
13
- Script(type="text/javascript", src="https://viewer.diagrams.net/js/viewer-static.min.js"),
14
- )
@@ -1,168 +0,0 @@
1
- """Agent History Explorer built with MonsterUI"""
2
-
3
- import json
4
- from datetime import datetime
5
-
6
- from fasthtml.common import *
7
- from monsterui.all import *
8
-
9
-
10
- def load_history(page=1, per_page=10, search=None):
11
- with open("data/history.json") as f:
12
- data = json.load(f)
13
-
14
- if search:
15
- search = search.lower()
16
- data = [
17
- d
18
- for d in data
19
- if search in d["agent_name"].lower() or search in d["location"].lower() or search in d["date"].lower()
20
- ]
21
-
22
- total = len(data)
23
- pages = (total + per_page - 1) // per_page
24
- start = (page - 1) * per_page
25
- return {"data": data[start : start + per_page], "total": total, "pages": pages, "page": page}
26
-
27
-
28
- def format_date(iso_date):
29
- return datetime.fromisoformat(iso_date).strftime("%b %d, %Y %H:%M")
30
-
31
-
32
- def json_preview(value):
33
- return Pre(json.dumps(value, indent=2), cls="text-xs p-2 bg-muted rounded-md max-h-40 overflow-auto")
34
-
35
-
36
- def header_render(col):
37
- return Th(col, cls="p-2 text-left")
38
-
39
-
40
- def cell_render(col, val):
41
- """Modified cell renderer that only uses column value"""
42
- match col:
43
- case "Agent":
44
- return Td(cls="p-2 font-medium")(Div(val))
45
- case "Date":
46
- return Td(cls="p-2 text-sm")(format_date(val))
47
- case "Location":
48
- return Td(cls="p-2 capitalize")(val) # val is already location string
49
- case "Input" | "Output":
50
- return Td(cls="p-2")(json_preview(val))
51
- case "Details":
52
- # val contains the full record here
53
- return Td(cls="p-2")(Button("View", cls=ButtonT.primary, uk_toggle=f"target: #details-{val['agent_id']}"))
54
-
55
-
56
- def details_modal(record):
57
- return Modal(
58
- Div(cls="p-6 space-y-4")(
59
- ModalTitle(f"{record['agent_name']} - {format_date(record['date'])}"),
60
- Grid(
61
- Div(cls="space-y-2")(H4("Input Details", cls="text-sm font-medium"), json_preview(record["input"])),
62
- Div(cls="space-y-2")(H4("Output Details", cls="text-sm font-medium"), json_preview(record["output"])),
63
- ),
64
- DivRAligned(ModalCloseButton("Close", cls=ButtonT.ghost)),
65
- ),
66
- id=f"details-{record['agent_id']}",
67
- )
68
-
69
-
70
- def get_history(page: int = 1, per_page: int = 5, search: str = None, reduced=False):
71
- history = load_history(page, per_page, search)
72
-
73
- controls = DivFullySpaced(cls="mt-8")(
74
- Div(cls="flex gap-4 items-center")(
75
- Input(
76
- placeholder="Search agents...",
77
- value=search,
78
- name="search",
79
- hx_get="/history",
80
- hx_trigger="keyup changed delay:500ms",
81
- hx_target="#history-content",
82
- hx_include="[name='per_page']",
83
- cls="w-64",
84
- ),
85
- Select(
86
- Option("5", value="5"),
87
- Option("10", value="10"),
88
- Option("20", value="20"),
89
- name="per_page",
90
- value=str(per_page),
91
- hx_get="/history",
92
- hx_trigger="change",
93
- hx_target="#history-content",
94
- cls="w-24",
95
- ),
96
- )
97
- )
98
-
99
- if reduced:
100
- header_data = ["Agent", "Date", "Details"]
101
- bodydata = [
102
- {
103
- "Agent": d["agent_name"],
104
- "Date": d["date"],
105
- "Details": d, # Store full record here
106
- }
107
- for d in history["data"]
108
- ]
109
- else:
110
- header_data = ["Agent", "Date", "Input", "Output", "Details"]
111
- bodydata = [
112
- {
113
- "Agent": d["agent_name"],
114
- "Date": d["date"],
115
- # "Location": d["input"]["location"], # Pre-extract location
116
- "Input": d["input"],
117
- "Output": d["output"],
118
- "Details": d, # Store full record here
119
- }
120
- for d in history["data"]
121
- ]
122
-
123
- table = TableFromDicts(
124
- header_data=header_data,
125
- body_data=bodydata,
126
- body_cell_render=cell_render,
127
- header_cell_render=header_render,
128
- cls=TableT.responsive,
129
- )
130
-
131
- footer = DivFullySpaced(cls="mt-4")(
132
- Div(
133
- f"Showing {min(history['total'], per_page)} of {history['total']} records",
134
- cls="text-sm text-muted-foreground",
135
- ),
136
- Div(cls="flex items-center gap-4")(
137
- Button(
138
- "< Prev",
139
- hx_get=f"/history?page={history['page'] - 1}",
140
- hx_target="#history-content",
141
- disabled=history["page"] == 1,
142
- cls=ButtonT.primary,
143
- ),
144
- Span(f"Page {history['page']} of {history['pages']}"),
145
- Button(
146
- "Next >",
147
- hx_get=f"/history?page={history['page'] + 1}",
148
- hx_target="#history-content",
149
- disabled=history["page"] == history["pages"],
150
- cls=ButtonT.primary,
151
- ),
152
- ),
153
- )
154
-
155
- return Div(id="history-content")(controls, table, footer, *[details_modal(d) for d in history["data"]])
156
-
157
-
158
- def HistoryGrid(reduced=False):
159
- if reduced:
160
- return get_history(reduced)
161
-
162
- return Div(cls="flex flex-col")(
163
- Div(cls="px-4 py-2 ")(
164
- H3("Agent History Explorer"),
165
- P("Review historical agent executions and their outcomes", cls=TextFont.muted_sm),
166
- ),
167
- get_history(reduced),
168
- )