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
flock/core/flock.py CHANGED
@@ -1,208 +1,232 @@
1
- # src/your_package/core/manager.py
2
- import contextlib
3
- import os
4
- import uuid
5
- from typing import TypeVar
6
-
7
- from flock.core.agent_registry import Registry
8
- from flock.core.context import FlockContext
9
- from flock.core.context_vars import FLOCK_CURRENT_AGENT, FLOCK_INITIAL_INPUT, FLOCK_LOCAL_DEBUG, FLOCK_RUN_ID
10
- from flock.core.logging import flock_logger, performance_handler
11
- from flock.core.logging.formatters import AgentResultFormatter
12
- from flock.core.logging.logger import FlockLogger, LogLevel
13
- from flock.workflow.activities import run_agent
14
- from flock.workflow.temporal_setup import create_temporal_client, setup_worker
15
- from flock.workflow.workflow import FlockWorkflow
16
-
17
- from .agent import Agent
18
-
19
- T = TypeVar("T", bound=Agent)
20
-
21
-
22
- class Flock:
23
- """Manages creation and execution of agents.
24
- This is a high-level class that the user interacts with directly.
25
- """
26
-
27
- def __init__(
28
- self,
29
- model: str = "openai/gpt-4o",
30
- log_level: int = LogLevel.MINIMAL,
31
- enable_performance_tracking: bool = False,
32
- local_debug: bool = False,
33
- ):
34
- """Initialize the Flock.
35
-
36
- Args:
37
- model: The default model to use for agents.
38
- log_level: The logging verbosity level:
39
- - LogLevel.NONE: No logging except errors
40
- - LogLevel.MINIMAL: Only agent outputs (default)
41
- - LogLevel.BASIC: Agent outputs + basic workflow info
42
- - LogLevel.VERBOSE: Everything including debug info
43
- log_format: The logging format to use:
44
- - LogFormat.SIMPLE: Simple message format (default)
45
- - LogFormat.STRUCTURED: Table-like structured format
46
- enable_performance_tracking: Whether to track and display performance metrics.
47
- local_debug: Whether to run in local debug mode (default: False).
48
- """
49
- self.agents: dict[str, Agent] = {}
50
- self.registry = Registry()
51
- self.context = FlockContext()
52
- self.model = model
53
- self.enable_performance_tracking = enable_performance_tracking
54
- self.local_debug = local_debug
55
-
56
- # Configure performance tracking
57
- if enable_performance_tracking:
58
- performance_handler.enable()
59
- else:
60
- performance_handler.disable()
61
-
62
- # Set LOCAL_DEBUG environment variable for console detection
63
- if local_debug:
64
- os.environ["LOCAL_DEBUG"] = "1"
65
- elif "LOCAL_DEBUG" in os.environ:
66
- del os.environ["LOCAL_DEBUG"]
67
-
68
- # Configure logging
69
- global flock_logger
70
- flock_logger = FlockLogger(level=log_level)
71
- flock_logger.info("Initialized Flock", model=model, local_debug=local_debug)
72
-
73
- def add_agent(self, agent: T) -> T:
74
- if not agent.model:
75
- agent.model = self.model
76
-
77
- if agent.name in self.agents:
78
- flock_logger.debug(f"Agent {agent.name} already exists, returning existing instance")
79
- return self.agents[agent.name]
80
-
81
- self.agents[agent.name] = agent
82
- self.registry.register_agent(agent)
83
- self.context.add_agent_definition(type(agent), agent.name, agent.to_dict())
84
- if hasattr(agent, "tools") and agent.tools:
85
- for tool in agent.tools:
86
- self.registry.register_tool(tool.__name__, tool)
87
- flock_logger.debug(f"Registered tool: {tool.__name__}")
88
-
89
- flock_logger.info(f"Added agent: {agent.name}", model=agent.model)
90
- return agent
91
-
92
- def add_tool(self, tool_name: str, tool: callable):
93
- self.registry.register_tool(tool_name, tool)
94
- flock_logger.debug(f"Registered tool: {tool_name}")
95
-
96
- async def _run_local_debug_workflow(self, box_result: bool = True):
97
- if self.enable_performance_tracking:
98
- perf_context = performance_handler.track_time("local_workflow")
99
- else:
100
- perf_context = contextlib.nullcontext()
101
-
102
- with perf_context:
103
- flock_logger.info("Running workflow in local debug mode")
104
- result = await run_agent(self.context)
105
-
106
- # Format and display the result (always shown regardless of log level)
107
- agent_name = self.context.get_variable(FLOCK_CURRENT_AGENT)
108
- AgentResultFormatter.print_result(result, agent_name)
109
-
110
- if self.enable_performance_tracking:
111
- performance_handler.display_timings()
112
-
113
- if box_result:
114
- from box import Box
115
-
116
- flock_logger.debug("Boxing result")
117
- return Box(result)
118
- return result
119
-
120
- async def _run_temporal_workflow(self, box_result: bool = True):
121
- if self.enable_performance_tracking:
122
- perf_context = performance_handler.track_time("temporal_workflow")
123
- else:
124
- perf_context = contextlib.nullcontext()
125
-
126
- with perf_context:
127
- flock_logger.info("Connecting to Temporal and starting worker...")
128
-
129
- await setup_worker(workflow=FlockWorkflow, activity=run_agent)
130
-
131
- flock_logger.info("Starting workflow execution")
132
-
133
- flock_client = await create_temporal_client()
134
- result = await flock_client.execute_workflow(
135
- FlockWorkflow.run,
136
- self.context.to_dict(),
137
- id=self.context.get_variable(FLOCK_RUN_ID),
138
- task_queue="flock-queue",
139
- )
140
-
141
- # Format and display the result (always shown regardless of log level)
142
- agent_name = self.context.get_variable(FLOCK_CURRENT_AGENT)
143
- flock_logger.result(result, agent_name)
144
-
145
- if self.enable_performance_tracking:
146
- performance_handler.display_timings()
147
-
148
- if box_result:
149
- from box import Box
150
-
151
- flock_logger.debug("Boxing result")
152
- return Box(result)
153
- return result
154
-
155
- async def run_async(
156
- self,
157
- start_agent: Agent | str,
158
- input: str,
159
- context: FlockContext = None,
160
- run_id: str = "",
161
- box_result: bool = True,
162
- ) -> dict:
163
- """Entry point for running an agent system."""
164
- try:
165
- if self.enable_performance_tracking:
166
- perf_context = performance_handler.track_time("run_setup")
167
- else:
168
- perf_context = contextlib.nullcontext()
169
-
170
- with perf_context:
171
- if isinstance(start_agent, str):
172
- flock_logger.debug(f"Looking up agent by name: {start_agent}")
173
- start_agent = self.registry.get_agent(start_agent)
174
- if not start_agent:
175
- raise ValueError(f"Agent '{start_agent}' not found in registry")
176
-
177
- if context:
178
- flock_logger.debug("Using provided context")
179
- self.context = context
180
-
181
- flock_logger.info("Setting up run context", agent=start_agent.name, input=input)
182
- self.context.set_variable(FLOCK_CURRENT_AGENT, start_agent.name)
183
- self.context.set_variable(FLOCK_INITIAL_INPUT, input)
184
- self.context.set_variable(FLOCK_LOCAL_DEBUG, self.local_debug)
185
-
186
- if not run_id:
187
- run_id = start_agent.name + "_" + uuid.uuid4().hex[:4]
188
- flock_logger.debug(f"Generated run ID: {run_id}")
189
-
190
- self.context.set_variable(FLOCK_RUN_ID, run_id)
191
-
192
- if self.enable_performance_tracking:
193
- performance_handler.display_timings()
194
-
195
- # we can run the flow locally for debugging purposes
196
- if self.local_debug:
197
- return await self._run_local_debug_workflow(box_result)
198
- else:
199
- return await self._run_temporal_workflow(box_result)
200
-
201
- except Exception as e:
202
- flock_logger.error(
203
- "Run failed",
204
- error=str(e),
205
- agent=getattr(start_agent, "name", str(start_agent)),
206
- input=input,
207
- )
208
- raise
1
+ """High-level orchestrator for creating and executing agents."""
2
+
3
+ import os
4
+ import uuid
5
+ from typing import TypeVar
6
+
7
+ from opentelemetry import trace
8
+ from rich.prompt import Prompt
9
+
10
+ from flock.core.context.context import FlockContext
11
+ from flock.core.context.context_manager import initialize_context
12
+ from flock.core.execution.local_executor import run_local_workflow
13
+ from flock.core.execution.temporal_executor import run_temporal_workflow
14
+ from flock.core.flock_agent import FlockAgent
15
+ from flock.core.logging.formatters.base_formatter import FormatterOptions
16
+ from flock.core.logging.formatters.pprint_formatter import PrettyPrintFormatter
17
+ from flock.core.logging.logging import get_logger
18
+ from flock.core.logging.telemetry import setup_tracing
19
+ from flock.core.registry.agent_registry import Registry
20
+ from flock.core.util.cli_helper import display_banner
21
+ from flock.core.util.input_resolver import top_level_to_keys
22
+
23
+ T = TypeVar("T", bound=FlockAgent)
24
+ logger = get_logger("flock")
25
+ tracer = setup_tracing()
26
+ tracer = trace.get_tracer(__name__)
27
+
28
+
29
+ class Flock:
30
+ """High-level orchestrator for creating and executing agents.
31
+
32
+ Flock manages the registration of agents and tools, sets up the global context, and runs the agent workflows.
33
+ It provides an easy-to-use API for both local (debug) and production (Temporal) execution.
34
+ """
35
+
36
+ def __init__(
37
+ self,
38
+ model: str = "openai/gpt-4o",
39
+ local_debug: bool = False,
40
+ enable_logging: bool = False,
41
+ output_formatter: FormatterOptions = FormatterOptions(
42
+ PrettyPrintFormatter
43
+ ),
44
+ ):
45
+ """Initialize the Flock orchestrator.
46
+
47
+ Args:
48
+ model (str): The default model identifier to be used for agents. Defaults to "openai/gpt-4o".
49
+ local_debug (bool): If True, run the agent workflow locally for debugging purposes. Defaults to False.
50
+ enable_logging (bool): If True, enable verbose logging. Defaults to False.
51
+ output_formatter (FormatterOptions): Options for formatting output results.
52
+ """
53
+ with tracer.start_as_current_span("flock_init") as span:
54
+ span.set_attribute("model", model)
55
+ span.set_attribute("local_debug", local_debug)
56
+ span.set_attribute("enable_logging", enable_logging)
57
+ span.set_attribute(
58
+ "output_formatter", output_formatter.formatter.__name__
59
+ )
60
+ logger.info(
61
+ "Initializing Flock",
62
+ model=model,
63
+ local_debug=local_debug,
64
+ enable_logging=enable_logging,
65
+ )
66
+ logger.enable_logging = enable_logging
67
+
68
+ display_banner()
69
+
70
+ self.agents: dict[str, FlockAgent] = {}
71
+ self.registry = Registry()
72
+ self.context = FlockContext()
73
+ self.model = model
74
+ self.local_debug = local_debug
75
+ self.output_formatter = output_formatter
76
+
77
+ if local_debug:
78
+ os.environ["LOCAL_DEBUG"] = "1"
79
+ logger.debug("Set LOCAL_DEBUG environment variable")
80
+ elif "LOCAL_DEBUG" in os.environ:
81
+ del os.environ["LOCAL_DEBUG"]
82
+ logger.debug("Removed LOCAL_DEBUG environment variable")
83
+
84
+ def add_agent(self, agent: T) -> T:
85
+ """Add a new agent to the Flock system.
86
+
87
+ This method registers the agent, updates the internal registry and global context, and
88
+ sets default values if needed. If an agent with the same name already exists, the existing
89
+ agent is returned.
90
+
91
+ Args:
92
+ agent (FlockAgent): The agent instance to add.
93
+
94
+ Returns:
95
+ FlockAgent: The registered agent instance.
96
+ """
97
+ if not agent.model:
98
+ agent.model = self.model
99
+ logger.debug(
100
+ f"Using default model for agent {agent.name}", model=self.model
101
+ )
102
+
103
+ if agent.name in self.agents:
104
+ logger.warning(
105
+ f"Agent {agent.name} already exists, returning existing instance"
106
+ )
107
+ return self.agents[agent.name]
108
+ logger.info("Adding new agent")
109
+
110
+ self.agents[agent.name] = agent
111
+ self.registry.register_agent(agent)
112
+ self.context.add_agent_definition(
113
+ type(agent), agent.name, agent.to_dict()
114
+ )
115
+
116
+ if hasattr(agent, "tools") and agent.tools:
117
+ for tool in agent.tools:
118
+ self.registry.register_tool(tool.__name__, tool)
119
+ logger.debug("Registered tool", tool_name=tool.__name__)
120
+ logger.success("Agent added successfully")
121
+ return agent
122
+
123
+ def add_tool(self, tool_name: str, tool: callable):
124
+ """Register a tool with the Flock system.
125
+
126
+ Args:
127
+ tool_name (str): The name under which the tool will be registered.
128
+ tool (callable): The tool function to register.
129
+ """
130
+ logger.info("Registering tool", tool_name=tool_name)
131
+ self.registry.register_tool(tool_name, tool)
132
+ logger.debug("Tool registered successfully")
133
+
134
+ async def run_async(
135
+ self,
136
+ start_agent: FlockAgent | str,
137
+ input: dict = {},
138
+ context: FlockContext = None,
139
+ run_id: str = "",
140
+ box_result: bool = True,
141
+ ) -> dict:
142
+ """Entry point for running an agent system asynchronously.
143
+
144
+ This method performs the following steps:
145
+ 1. If a string is provided for start_agent, it looks up the agent in the registry.
146
+ 2. Optionally uses a provided global context.
147
+ 3. Generates a unique run ID if one is not provided.
148
+ 4. Initializes the context with standard variables (like agent name, input data, run ID, and debug flag).
149
+ 5. Executes the agent workflow either locally (for debugging) or via Temporal (for production).
150
+
151
+ Args:
152
+ start_agent (FlockAgent | str): The agent instance or the name of the agent to start the workflow.
153
+ input (dict): A dictionary of input values required by the agent.
154
+ context (FlockContext, optional): A FlockContext instance to use. If not provided, a default context is used.
155
+ run_id (str, optional): A unique identifier for this run. If empty, one is generated automatically.
156
+ box_result (bool, optional): If True, wraps the output in a Box for nicer formatting. Defaults to True.
157
+
158
+ Returns:
159
+ dict: A dictionary containing the result of the agent workflow execution.
160
+
161
+ Raises:
162
+ ValueError: If the specified agent is not found in the registry.
163
+ Exception: For any other errors encountered during execution.
164
+ """
165
+ with tracer.start_as_current_span("run_async") as span:
166
+ span.set_attribute(
167
+ "start_agent",
168
+ start_agent.name
169
+ if hasattr(start_agent, "name")
170
+ else start_agent,
171
+ )
172
+
173
+ span.set_attribute("input", str(input))
174
+ span.set_attribute("context", str(context))
175
+ span.set_attribute("run_id", run_id)
176
+ span.set_attribute("box_result", box_result)
177
+
178
+ try:
179
+ if isinstance(start_agent, str):
180
+ logger.debug(
181
+ "Looking up agent by name", agent_name=start_agent
182
+ )
183
+ start_agent = self.registry.get_agent(start_agent)
184
+ if not start_agent:
185
+ logger.error("Agent not found", agent_name=start_agent)
186
+ raise ValueError(
187
+ f"Agent '{start_agent}' not found in registry"
188
+ )
189
+ start_agent.resolve_callables(context=self.context)
190
+ if context:
191
+ logger.debug("Using provided context")
192
+ self.context = context
193
+ if not run_id:
194
+ run_id = f"{start_agent.name}_{uuid.uuid4().hex[:4]}"
195
+ logger.debug("Generated run ID", run_id=run_id)
196
+
197
+ # TODO - Add a check for required input keys
198
+ input_keys = top_level_to_keys(start_agent.input)
199
+ for key in input_keys:
200
+ if key.startswith("flock."):
201
+ key = key[6:] # Remove the "flock." prefix
202
+ if key not in input:
203
+ input[key] = Prompt.ask(
204
+ f"Please enter {key} for {start_agent.name}"
205
+ )
206
+
207
+ # Initialize the context with standardized variables
208
+ initialize_context(
209
+ self.context,
210
+ start_agent.name,
211
+ input,
212
+ run_id,
213
+ self.local_debug,
214
+ )
215
+
216
+ logger.info(
217
+ "Starting agent execution",
218
+ agent=start_agent.name,
219
+ local_debug=self.local_debug,
220
+ )
221
+
222
+ if self.local_debug:
223
+ return await run_local_workflow(
224
+ self.context, self.output_formatter, box_result
225
+ )
226
+ else:
227
+ return await run_temporal_workflow(
228
+ self.context, self.output_formatter, box_result
229
+ )
230
+ except Exception as e:
231
+ logger.exception("Execution failed", error=str(e))
232
+ raise