flock-core 0.1.1__py3-none-any.whl → 0.2.1__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.
- flock/__init__.py +1 -4
- flock/agents/__init__.py +0 -3
- flock/agents/batch_agent.py +140 -175
- flock/agents/loop_agent.py +117 -178
- flock/agents/trigger_agent.py +113 -191
- flock/agents/user_agent.py +145 -230
- flock/core/__init__.py +1 -7
- flock/core/context/context.py +211 -0
- flock/core/context/context_manager.py +34 -0
- flock/core/{context_vars.py → context/context_vars.py} +8 -6
- flock/core/execution/local_executor.py +27 -0
- flock/core/execution/temporal_executor.py +40 -0
- flock/core/flock.py +199 -208
- flock/core/flock_agent.py +492 -0
- flock/core/logging/__init__.py +2 -18
- flock/core/logging/formatters/base_formatter.py +36 -0
- flock/core/logging/formatters/formatter_factory.py +38 -0
- flock/core/logging/formatters/pprint_formatter.py +18 -0
- flock/core/logging/formatters/rich_formatters.py +132 -0
- flock/core/logging/formatters/theme_builder.py +480 -0
- flock/core/logging/formatters/themed_formatter.py +442 -0
- flock/core/logging/logging.py +123 -0
- flock/core/mixin/dspy_integration.py +171 -0
- flock/core/mixin/prompt_parser.py +125 -0
- flock/core/registry/agent_registry.py +103 -0
- flock/core/tools/basic_tools.py +273 -98
- flock/core/tools/dev_tools/github.py +161 -0
- flock/core/util/cli_helper.py +21 -0
- flock/core/util/input_resolver.py +156 -0
- flock/core/util/serializable.py +93 -0
- flock/themes/3024-day.toml +39 -0
- flock/themes/3024-night.toml +77 -0
- flock/themes/aardvark-blue.toml +77 -0
- flock/themes/abernathy.toml +77 -0
- flock/themes/adventure.toml +77 -0
- flock/themes/adventuretime.toml +77 -0
- flock/themes/afterglow.toml +77 -0
- flock/themes/alabaster.toml +77 -0
- flock/themes/alienblood.toml +77 -0
- flock/themes/andromeda.toml +77 -0
- flock/themes/apple-classic.toml +77 -0
- flock/themes/apple-system-colors.toml +77 -0
- flock/themes/arcoiris.toml +77 -0
- flock/themes/argonaut copy.toml +77 -0
- flock/themes/argonaut.toml +39 -0
- flock/themes/arthur.toml +77 -0
- flock/themes/ateliersulphurpool.toml +77 -0
- flock/themes/atom.toml +38 -0
- flock/themes/atom_test.toml +65 -0
- flock/themes/atomonelight.toml +77 -0
- flock/themes/aurora.toml +77 -0
- flock/themes/ayu copy.toml +77 -0
- flock/themes/ayu-light.toml +77 -0
- flock/themes/ayu-mirage.toml +77 -0
- flock/themes/ayu.toml +39 -0
- flock/themes/banana-blueberry.toml +77 -0
- flock/themes/batman.toml +77 -0
- flock/themes/belafonte-day.toml +77 -0
- flock/themes/belafonte-night.toml +77 -0
- flock/themes/birdsofparadise.toml +77 -0
- flock/themes/blazer.toml +77 -0
- flock/themes/blue-matrix.toml +77 -0
- flock/themes/blueberrypie.toml +77 -0
- flock/themes/bluedolphin.toml +77 -0
- flock/themes/blulocodark.toml +77 -0
- flock/themes/blulocolight.toml +77 -0
- flock/themes/borland.toml +77 -0
- flock/themes/breeze.toml +77 -0
- flock/themes/bright-lights.toml +77 -0
- flock/themes/broadcast.toml +77 -0
- flock/themes/brogrammer.toml +77 -0
- flock/themes/builtin-dark.toml +77 -0
- flock/themes/builtin-light.toml +77 -0
- flock/themes/builtin-pastel-dark.toml +77 -0
- flock/themes/builtin-solarized-dark.toml +77 -0
- flock/themes/builtin-solarized-light.toml +77 -0
- flock/themes/builtin-tango-dark.toml +77 -0
- flock/themes/builtin-tango-light.toml +77 -0
- flock/themes/c64.toml +77 -0
- flock/themes/calamity.toml +77 -0
- flock/themes/catppuccin-frappe.toml +77 -0
- flock/themes/catppuccin-latte.toml +77 -0
- flock/themes/catppuccin-macchiato.toml +77 -0
- flock/themes/catppuccin-mocha.toml +77 -0
- flock/themes/cga.toml +77 -0
- flock/themes/chalk.toml +77 -0
- flock/themes/chalkboard.toml +77 -0
- flock/themes/challengerdeep.toml +77 -0
- flock/themes/chester.toml +77 -0
- flock/themes/ciapre.toml +77 -0
- flock/themes/clrs.toml +77 -0
- flock/themes/cobalt-neon.toml +77 -0
- flock/themes/cobalt2.toml +77 -0
- flock/themes/coffee-theme.toml +77 -0
- flock/themes/crayonponyfish.toml +77 -0
- flock/themes/cutiepro.toml +77 -0
- flock/themes/cyberdyne.toml +77 -0
- flock/themes/cyberpunk.toml +77 -0
- flock/themes/cyberpunkscarletprotocol.toml +77 -0
- flock/themes/dark+.toml +77 -0
- flock/themes/dark-pastel.toml +77 -0
- flock/themes/darkermatrix.toml +77 -0
- flock/themes/darkmatrix.toml +77 -0
- flock/themes/darkside.toml +77 -0
- flock/themes/dayfox.toml +77 -0
- flock/themes/deep.toml +77 -0
- flock/themes/desert.toml +77 -0
- flock/themes/dimidium.toml +77 -0
- flock/themes/dimmedmonokai.toml +77 -0
- flock/themes/django.toml +77 -0
- flock/themes/djangorebornagain.toml +77 -0
- flock/themes/djangosmooth.toml +77 -0
- flock/themes/doom-peacock.toml +77 -0
- flock/themes/doomone.toml +77 -0
- flock/themes/dotgov.toml +77 -0
- flock/themes/dracula+.toml +77 -0
- flock/themes/dracula.toml +77 -0
- flock/themes/duckbones.toml +77 -0
- flock/themes/duotone-dark.toml +77 -0
- flock/themes/earthsong.toml +77 -0
- flock/themes/elemental.toml +77 -0
- flock/themes/elementary.toml +77 -0
- flock/themes/encom.toml +77 -0
- flock/themes/espresso-libre.toml +77 -0
- flock/themes/espresso.toml +77 -0
- flock/themes/everblush.toml +77 -0
- flock/themes/fahrenheit.toml +77 -0
- flock/themes/fairyfloss.toml +77 -0
- flock/themes/farmhouse-dark.toml +77 -0
- flock/themes/farmhouse-light.toml +77 -0
- flock/themes/fideloper.toml +77 -0
- flock/themes/firefly-traditional.toml +77 -0
- flock/themes/firefoxdev.toml +77 -0
- flock/themes/firewatch.toml +77 -0
- flock/themes/fishtank.toml +77 -0
- flock/themes/flat.toml +77 -0
- flock/themes/flatland.toml +77 -0
- flock/themes/flexoki-dark.toml +77 -0
- flock/themes/flexoki-light.toml +77 -0
- flock/themes/floraverse.toml +77 -0
- flock/themes/forestblue.toml +77 -0
- flock/themes/framer.toml +77 -0
- flock/themes/frontenddelight.toml +77 -0
- flock/themes/funforrest.toml +77 -0
- flock/themes/galaxy.toml +77 -0
- flock/themes/galizur.toml +77 -0
- flock/themes/github-dark.toml +77 -0
- flock/themes/github.toml +77 -0
- flock/themes/glacier.toml +77 -0
- flock/themes/grape.toml +77 -0
- flock/themes/grass.toml +77 -0
- flock/themes/grey-green.toml +77 -0
- flock/themes/gruber-darker.toml +77 -0
- flock/themes/gruvboxdark.toml +77 -0
- flock/themes/gruvboxdarkhard.toml +77 -0
- flock/themes/gruvboxlight.toml +77 -0
- flock/themes/guezwhoz.toml +77 -0
- flock/themes/hacktober.toml +77 -0
- flock/themes/hardcore.toml +77 -0
- flock/themes/harper.toml +77 -0
- flock/themes/hax0r-blue.toml +77 -0
- flock/themes/hax0r-gr33n.toml +77 -0
- flock/themes/hax0r-r3d.toml +77 -0
- flock/themes/highway.toml +77 -0
- flock/themes/hipster-green.toml +77 -0
- flock/themes/hivacruz.toml +77 -0
- flock/themes/homebrew.toml +77 -0
- flock/themes/hopscotch.256.toml +77 -0
- flock/themes/hopscotch.toml +77 -0
- flock/themes/hurtado.toml +77 -0
- flock/themes/hybrid.toml +77 -0
- flock/themes/ic-green-ppl.toml +77 -0
- flock/themes/ic-orange-ppl.toml +77 -0
- flock/themes/iceberg-dark.toml +77 -0
- flock/themes/iceberg-light.toml +77 -0
- flock/themes/idea.toml +77 -0
- flock/themes/idletoes.toml +77 -0
- flock/themes/ir-black.toml +77 -0
- flock/themes/iterm2-dark-background.toml +77 -0
- flock/themes/iterm2-default.toml +77 -0
- flock/themes/iterm2-light-background.toml +77 -0
- flock/themes/iterm2-pastel-dark-background.toml +77 -0
- flock/themes/iterm2-smoooooth.toml +77 -0
- flock/themes/iterm2-solarized-dark.toml +77 -0
- flock/themes/iterm2-solarized-light.toml +77 -0
- flock/themes/iterm2-tango-dark.toml +77 -0
- flock/themes/iterm2-tango-light.toml +77 -0
- flock/themes/jackie-brown.toml +77 -0
- flock/themes/japanesque.toml +77 -0
- flock/themes/jellybeans.toml +77 -0
- flock/themes/jetbrains-darcula.toml +77 -0
- flock/themes/jubi.toml +77 -0
- flock/themes/kanagawabones.toml +77 -0
- flock/themes/kibble.toml +77 -0
- flock/themes/kolorit.toml +77 -0
- flock/themes/konsolas.toml +77 -0
- flock/themes/kurokula.toml +77 -0
- flock/themes/lab-fox.toml +77 -0
- flock/themes/laser.toml +77 -0
- flock/themes/later-this-evening.toml +77 -0
- flock/themes/lavandula.toml +77 -0
- flock/themes/liquidcarbon.toml +77 -0
- flock/themes/liquidcarbontransparent.toml +77 -0
- flock/themes/liquidcarbontransparentinverse.toml +77 -0
- flock/themes/lovelace.toml +77 -0
- flock/themes/man-page.toml +77 -0
- flock/themes/mariana.toml +77 -0
- flock/themes/material.toml +77 -0
- flock/themes/materialdark.toml +77 -0
- flock/themes/materialdarker.toml +77 -0
- flock/themes/materialdesigncolors.toml +77 -0
- flock/themes/materialocean.toml +77 -0
- flock/themes/mathias.toml +77 -0
- flock/themes/matrix.toml +77 -0
- flock/themes/medallion.toml +77 -0
- flock/themes/mellifluous.toml +77 -0
- flock/themes/midnight-in-mojave.toml +77 -0
- flock/themes/mirage.toml +77 -0
- flock/themes/misterioso.toml +77 -0
- flock/themes/molokai.toml +77 -0
- flock/themes/monalisa.toml +77 -0
- flock/themes/monokai-remastered.toml +77 -0
- flock/themes/monokai-soda.toml +77 -0
- flock/themes/monokai-vivid.toml +77 -0
- flock/themes/n0tch2k.toml +77 -0
- flock/themes/neobones-dark.toml +77 -0
- flock/themes/neobones-light.toml +77 -0
- flock/themes/neon.toml +77 -0
- flock/themes/neopolitan.toml +77 -0
- flock/themes/neutron.toml +77 -0
- flock/themes/night-owlish-light.toml +77 -0
- flock/themes/nightfox.toml +77 -0
- flock/themes/nightlion-v1.toml +77 -0
- flock/themes/nightlion-v2.toml +77 -0
- flock/themes/niji.toml +77 -0
- flock/themes/nocturnal-winter.toml +77 -0
- flock/themes/nord-light.toml +77 -0
- flock/themes/nord.toml +77 -0
- flock/themes/novel.toml +77 -0
- flock/themes/nvimdark.toml +77 -0
- flock/themes/nvimlight.toml +77 -0
- flock/themes/obsidian.toml +77 -0
- flock/themes/ocean.toml +77 -0
- flock/themes/oceanic-next.toml +77 -0
- flock/themes/oceanicmaterial.toml +77 -0
- flock/themes/ollie.toml +77 -0
- flock/themes/onehalfdark.toml +77 -0
- flock/themes/onehalflight.toml +77 -0
- flock/themes/operator-mono-dark.toml +77 -0
- flock/themes/overnight-slumber.toml +77 -0
- flock/themes/oxocarbon.toml +77 -0
- flock/themes/palenighthc.toml +77 -0
- flock/themes/pandora.toml +77 -0
- flock/themes/paraiso-dark.toml +77 -0
- flock/themes/paulmillr.toml +77 -0
- flock/themes/pencildark.toml +77 -0
- flock/themes/pencillight.toml +77 -0
- flock/themes/peppermint.toml +77 -0
- flock/themes/piatto-light.toml +77 -0
- flock/themes/pnevma.toml +77 -0
- flock/themes/popping-and-locking.toml +77 -0
- flock/themes/primary.toml +77 -0
- flock/themes/pro-light.toml +77 -0
- flock/themes/pro.toml +77 -0
- flock/themes/purple-rain.toml +77 -0
- flock/themes/purplepeter.toml +77 -0
- flock/themes/rapture.toml +77 -0
- flock/themes/raycast-dark.toml +77 -0
- flock/themes/raycast-light.toml +77 -0
- flock/themes/rebecca.toml +77 -0
- flock/themes/red-alert.toml +77 -0
- flock/themes/red-planet.toml +77 -0
- flock/themes/red-sands.toml +77 -0
- flock/themes/relaxed.toml +77 -0
- flock/themes/retro.toml +77 -0
- flock/themes/rippedcasts.toml +77 -0
- flock/themes/rose-pine-dawn.toml +77 -0
- flock/themes/rose-pine-moon.toml +77 -0
- flock/themes/rose-pine.toml +77 -0
- flock/themes/rouge-2.toml +77 -0
- flock/themes/royal.toml +77 -0
- flock/themes/ryuuko.toml +77 -0
- flock/themes/sakura.toml +77 -0
- flock/themes/scarlet-protocol.toml +77 -0
- flock/themes/seafoam-pastel.toml +77 -0
- flock/themes/seashells.toml +77 -0
- flock/themes/seoulbones-dark.toml +77 -0
- flock/themes/seoulbones-light.toml +77 -0
- flock/themes/seti.toml +77 -0
- flock/themes/shades-of-purple.toml +77 -0
- flock/themes/shaman.toml +77 -0
- flock/themes/slate.toml +77 -0
- flock/themes/sleepyhollow.toml +77 -0
- flock/themes/smyck.toml +77 -0
- flock/themes/snazzy.toml +77 -0
- flock/themes/softserver.toml +77 -0
- flock/themes/solarized-darcula.toml +77 -0
- flock/themes/solarized-dark---patched.toml +77 -0
- flock/themes/solarized-dark-higher-contrast.toml +77 -0
- flock/themes/spacedust.toml +77 -0
- flock/themes/spacegray-eighties-dull.toml +77 -0
- flock/themes/spacegray-eighties.toml +77 -0
- flock/themes/spacegray.toml +77 -0
- flock/themes/spiderman.toml +77 -0
- flock/themes/spring.toml +77 -0
- flock/themes/square.toml +77 -0
- flock/themes/sublette.toml +77 -0
- flock/themes/subliminal.toml +77 -0
- flock/themes/sugarplum.toml +77 -0
- flock/themes/sundried.toml +77 -0
- flock/themes/symfonic.toml +77 -0
- flock/themes/synthwave-everything.toml +77 -0
- flock/themes/synthwave.toml +77 -0
- flock/themes/synthwavealpha.toml +77 -0
- flock/themes/tango-adapted.toml +77 -0
- flock/themes/tango-half-adapted.toml +77 -0
- flock/themes/teerb.toml +77 -0
- flock/themes/terafox.toml +77 -0
- flock/themes/terminal-basic.toml +77 -0
- flock/themes/thayer-bright.toml +77 -0
- flock/themes/the-hulk.toml +77 -0
- flock/themes/tinacious-design-(dark).toml +77 -0
- flock/themes/tinacious-design-(light).toml +77 -0
- flock/themes/tokyonight-day.toml +77 -0
- flock/themes/tokyonight-storm.toml +77 -0
- flock/themes/tokyonight.toml +77 -0
- flock/themes/tomorrow-night-blue.toml +77 -0
- flock/themes/tomorrow-night-bright.toml +77 -0
- flock/themes/tomorrow-night-burns.toml +77 -0
- flock/themes/tomorrow-night-eighties.toml +77 -0
- flock/themes/tomorrow-night.toml +77 -0
- flock/themes/tomorrow.toml +77 -0
- flock/themes/toychest.toml +77 -0
- flock/themes/treehouse.toml +77 -0
- flock/themes/twilight.toml +77 -0
- flock/themes/ubuntu.toml +77 -0
- flock/themes/ultradark.toml +77 -0
- flock/themes/ultraviolent.toml +77 -0
- flock/themes/underthesea.toml +77 -0
- flock/themes/unikitty.toml +77 -0
- flock/themes/urple.toml +77 -0
- flock/themes/vaughn.toml +77 -0
- flock/themes/vesper.toml +77 -0
- flock/themes/vibrantink.toml +77 -0
- flock/themes/vimbones.toml +77 -0
- flock/themes/violet-dark.toml +77 -0
- flock/themes/violet-light.toml +77 -0
- flock/themes/warmneon.toml +77 -0
- flock/themes/wez.toml +77 -0
- flock/themes/whimsy.toml +77 -0
- flock/themes/wildcherry.toml +77 -0
- flock/themes/wilmersdorf.toml +77 -0
- flock/themes/wombat.toml +77 -0
- flock/themes/wryan.toml +77 -0
- flock/themes/xcodedark.toml +77 -0
- flock/themes/xcodedarkhc.toml +77 -0
- flock/themes/xcodelight.toml +77 -0
- flock/themes/xcodelighthc.toml +77 -0
- flock/themes/xcodewwdc.toml +77 -0
- flock/themes/zenbones-dark.toml +77 -0
- flock/themes/zenbones-light.toml +77 -0
- flock/themes/zenbones.toml +77 -0
- flock/themes/zenburn.toml +77 -0
- flock/themes/zenburned.toml +77 -0
- flock/themes/zenwritten-dark.toml +77 -0
- flock/themes/zenwritten-light.toml +77 -0
- flock/workflow/activities.py +117 -115
- flock/workflow/agent_activities.py +24 -26
- flock/workflow/temporal_setup.py +38 -37
- flock/workflow/workflow.py +58 -53
- flock_core-0.2.1.dist-info/METADATA +287 -0
- flock_core-0.2.1.dist-info/RECORD +375 -0
- {flock_core-0.1.1.dist-info → flock_core-0.2.1.dist-info}/licenses/LICENSE +21 -21
- flock/agents/declarative_agent.py +0 -166
- flock/app/components/__init__.py +0 -14
- flock/app/components/charts/agent_workflow.py +0 -14
- flock/app/components/charts/core_architecture.py +0 -14
- flock/app/components/charts/tool_system.py +0 -14
- flock/app/components/history_grid.py +0 -168
- flock/app/components/history_grid_alt.py +0 -189
- flock/app/components/sidebar.py +0 -19
- flock/app/components/theme.py +0 -9
- flock/app/components/util.py +0 -18
- flock/app/hive_app.py +0 -118
- flock/app/html/d3.html +0 -179
- flock/app/modules/__init__.py +0 -12
- flock/app/modules/about.py +0 -17
- flock/app/modules/agent_detail.py +0 -70
- flock/app/modules/agent_list.py +0 -59
- flock/app/modules/playground.py +0 -322
- flock/app/modules/settings.py +0 -96
- flock/core/agent.py +0 -150
- flock/core/agent_registry.py +0 -162
- flock/core/context.py +0 -279
- flock/core/handoff/handoff_base.py +0 -12
- flock/core/logging/error_handler.py +0 -84
- flock/core/logging/formatters.py +0 -122
- flock/core/logging/handlers.py +0 -117
- flock/core/logging/logger.py +0 -107
- flock/core/serializable.py +0 -206
- flock_core-0.1.1.dist-info/METADATA +0 -449
- flock_core-0.1.1.dist-info/RECORD +0 -48
- flock_core-0.1.1.dist-info/entry_points.txt +0 -2
- /flock/{core/config/declarative_agent_config.py → workflow/__init__.py} +0 -0
- {flock_core-0.1.1.dist-info → flock_core-0.2.1.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# src/your_package/core/execution/local_executor.py
|
|
2
|
+
from flock.core.context.context import FlockContext
|
|
3
|
+
from flock.core.logging.logging import get_logger
|
|
4
|
+
from flock.workflow.activities import run_agent # This should be the local activity function
|
|
5
|
+
|
|
6
|
+
logger = get_logger("flock")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def run_local_workflow(context: FlockContext, output_formatter, box_result: bool = True) -> dict:
|
|
10
|
+
"""Execute the agent workflow locally (for debugging).
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
context: The FlockContext instance with state and history.
|
|
14
|
+
output_formatter: Formatter options for displaying results.
|
|
15
|
+
box_result: If True, wraps the result in a Box for nicer display.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
A dictionary containing the workflow result.
|
|
19
|
+
"""
|
|
20
|
+
logger.info("Running local debug workflow")
|
|
21
|
+
result = await run_agent(context, output_formatter)
|
|
22
|
+
if box_result:
|
|
23
|
+
from box import Box
|
|
24
|
+
|
|
25
|
+
logger.debug("Boxing result")
|
|
26
|
+
return Box(result)
|
|
27
|
+
return result
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# src/your_package/core/execution/temporal_executor.py
|
|
2
|
+
from flock.core.context.context import FlockContext
|
|
3
|
+
from flock.core.logging.logging import get_logger
|
|
4
|
+
from flock.workflow.activities import run_agent # Activity function used in Temporal
|
|
5
|
+
from flock.workflow.temporal_setup import create_temporal_client, setup_worker
|
|
6
|
+
from flock.workflow.workflow import FlockWorkflow # Your workflow class
|
|
7
|
+
|
|
8
|
+
logger = get_logger("flock")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def run_temporal_workflow(context: FlockContext, box_result: bool = True) -> dict:
|
|
12
|
+
"""Execute the agent workflow via Temporal for robust, distributed processing.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
context: The FlockContext instance with state and history.
|
|
16
|
+
box_result: If True, wraps the result in a Box for nicer display.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
A dictionary containing the workflow result.
|
|
20
|
+
"""
|
|
21
|
+
logger.info("Setting up Temporal workflow")
|
|
22
|
+
await setup_worker(workflow=FlockWorkflow, activity=run_agent)
|
|
23
|
+
logger.debug("Creating Temporal client")
|
|
24
|
+
flock_client = await create_temporal_client()
|
|
25
|
+
workflow_id = context.get_variable("FLOCK_RUN_ID")
|
|
26
|
+
logger.info("Executing Temporal workflow", workflow_id=workflow_id)
|
|
27
|
+
result = await flock_client.execute_workflow(
|
|
28
|
+
FlockWorkflow.run, context.to_dict(), id=workflow_id, task_queue="flock-queue"
|
|
29
|
+
)
|
|
30
|
+
from flock.core.logging.formatters.themed_formatter import ThemedAgentResultFormatter
|
|
31
|
+
|
|
32
|
+
agent_name = context.get_variable("FLOCK_CURRENT_AGENT")
|
|
33
|
+
logger.debug("Formatting Temporal result", agent=agent_name)
|
|
34
|
+
ThemedAgentResultFormatter.print_result(result, agent_name)
|
|
35
|
+
if box_result:
|
|
36
|
+
from box import Box
|
|
37
|
+
|
|
38
|
+
logger.debug("Boxing Temporal result")
|
|
39
|
+
return Box(result)
|
|
40
|
+
return result
|
flock/core/flock.py
CHANGED
|
@@ -1,208 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import uuid
|
|
5
|
-
from typing import TypeVar
|
|
6
|
-
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
from flock.core.
|
|
10
|
-
from flock.core.
|
|
11
|
-
from flock.core.
|
|
12
|
-
from flock.core.
|
|
13
|
-
from flock.
|
|
14
|
-
from flock.
|
|
15
|
-
from flock.
|
|
16
|
-
|
|
17
|
-
from .
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
""
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def add_agent(self, agent: T) -> T:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if agent
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
self.context
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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 rich.prompt import Prompt
|
|
8
|
+
|
|
9
|
+
from flock.core.context.context import FlockContext
|
|
10
|
+
from flock.core.context.context_manager import initialize_context
|
|
11
|
+
from flock.core.execution.local_executor import run_local_workflow
|
|
12
|
+
from flock.core.execution.temporal_executor import run_temporal_workflow
|
|
13
|
+
from flock.core.flock_agent import FlockAgent
|
|
14
|
+
from flock.core.logging.formatters.base_formatter import FormatterOptions
|
|
15
|
+
from flock.core.logging.formatters.pprint_formatter import PrettyPrintFormatter
|
|
16
|
+
from flock.core.logging.logging import get_logger
|
|
17
|
+
from flock.core.registry.agent_registry import Registry
|
|
18
|
+
from flock.core.util.cli_helper import display_banner
|
|
19
|
+
from flock.core.util.input_resolver import top_level_to_keys
|
|
20
|
+
|
|
21
|
+
T = TypeVar("T", bound=FlockAgent)
|
|
22
|
+
logger = get_logger("flock")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Flock:
|
|
26
|
+
"""High-level orchestrator for creating and executing agents.
|
|
27
|
+
|
|
28
|
+
Flock manages the registration of agents and tools, sets up the global context, and runs the agent workflows.
|
|
29
|
+
It provides an easy-to-use API for both local (debug) and production (Temporal) execution.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
model: str = "openai/gpt-4o",
|
|
35
|
+
local_debug: bool = False,
|
|
36
|
+
enable_logging: bool = False,
|
|
37
|
+
output_formatter: FormatterOptions = FormatterOptions(
|
|
38
|
+
PrettyPrintFormatter
|
|
39
|
+
),
|
|
40
|
+
):
|
|
41
|
+
"""Initialize the Flock orchestrator.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
model (str): The default model identifier to be used for agents. Defaults to "openai/gpt-4o".
|
|
45
|
+
local_debug (bool): If True, run the agent workflow locally for debugging purposes. Defaults to False.
|
|
46
|
+
enable_logging (bool): If True, enable verbose logging. Defaults to False.
|
|
47
|
+
output_formatter (FormatterOptions): Options for formatting output results.
|
|
48
|
+
"""
|
|
49
|
+
logger.info(
|
|
50
|
+
"Initializing Flock",
|
|
51
|
+
model=model,
|
|
52
|
+
local_debug=local_debug,
|
|
53
|
+
enable_logging=enable_logging,
|
|
54
|
+
)
|
|
55
|
+
logger.enable_logging = enable_logging
|
|
56
|
+
|
|
57
|
+
display_banner()
|
|
58
|
+
|
|
59
|
+
self.agents: dict[str, FlockAgent] = {}
|
|
60
|
+
self.registry = Registry()
|
|
61
|
+
self.context = FlockContext()
|
|
62
|
+
self.model = model
|
|
63
|
+
self.local_debug = local_debug
|
|
64
|
+
self.output_formatter = output_formatter
|
|
65
|
+
|
|
66
|
+
if local_debug:
|
|
67
|
+
os.environ["LOCAL_DEBUG"] = "1"
|
|
68
|
+
logger.debug("Set LOCAL_DEBUG environment variable")
|
|
69
|
+
elif "LOCAL_DEBUG" in os.environ:
|
|
70
|
+
del os.environ["LOCAL_DEBUG"]
|
|
71
|
+
logger.debug("Removed LOCAL_DEBUG environment variable")
|
|
72
|
+
|
|
73
|
+
def add_agent(self, agent: T) -> T:
|
|
74
|
+
"""Add a new agent to the Flock system.
|
|
75
|
+
|
|
76
|
+
This method registers the agent, updates the internal registry and global context, and
|
|
77
|
+
sets default values if needed. If an agent with the same name already exists, the existing
|
|
78
|
+
agent is returned.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
agent (FlockAgent): The agent instance to add.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
FlockAgent: The registered agent instance.
|
|
85
|
+
"""
|
|
86
|
+
if not agent.model:
|
|
87
|
+
agent.model = self.model
|
|
88
|
+
logger.debug(
|
|
89
|
+
f"Using default model for agent {agent.name}", model=self.model
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if agent.name in self.agents:
|
|
93
|
+
logger.warning(
|
|
94
|
+
f"Agent {agent.name} already exists, returning existing instance"
|
|
95
|
+
)
|
|
96
|
+
return self.agents[agent.name]
|
|
97
|
+
logger.info("Adding new agent")
|
|
98
|
+
|
|
99
|
+
self.agents[agent.name] = agent
|
|
100
|
+
self.registry.register_agent(agent)
|
|
101
|
+
self.context.add_agent_definition(
|
|
102
|
+
type(agent), agent.name, agent.to_dict()
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
if hasattr(agent, "tools") and agent.tools:
|
|
106
|
+
for tool in agent.tools:
|
|
107
|
+
self.registry.register_tool(tool.__name__, tool)
|
|
108
|
+
logger.debug("Registered tool", tool_name=tool.__name__)
|
|
109
|
+
logger.success("Agent added successfully")
|
|
110
|
+
return agent
|
|
111
|
+
|
|
112
|
+
def add_tool(self, tool_name: str, tool: callable):
|
|
113
|
+
"""Register a tool with the Flock system.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
tool_name (str): The name under which the tool will be registered.
|
|
117
|
+
tool (callable): The tool function to register.
|
|
118
|
+
"""
|
|
119
|
+
logger.info("Registering tool", tool_name=tool_name)
|
|
120
|
+
self.registry.register_tool(tool_name, tool)
|
|
121
|
+
logger.debug("Tool registered successfully")
|
|
122
|
+
|
|
123
|
+
async def run_async(
|
|
124
|
+
self,
|
|
125
|
+
start_agent: FlockAgent | str,
|
|
126
|
+
input: dict = {},
|
|
127
|
+
context: FlockContext = None,
|
|
128
|
+
run_id: str = "",
|
|
129
|
+
box_result: bool = True,
|
|
130
|
+
) -> dict:
|
|
131
|
+
"""Entry point for running an agent system asynchronously.
|
|
132
|
+
|
|
133
|
+
This method performs the following steps:
|
|
134
|
+
1. If a string is provided for start_agent, it looks up the agent in the registry.
|
|
135
|
+
2. Optionally uses a provided global context.
|
|
136
|
+
3. Generates a unique run ID if one is not provided.
|
|
137
|
+
4. Initializes the context with standard variables (like agent name, input data, run ID, and debug flag).
|
|
138
|
+
5. Executes the agent workflow either locally (for debugging) or via Temporal (for production).
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
start_agent (FlockAgent | str): The agent instance or the name of the agent to start the workflow.
|
|
142
|
+
input (dict): A dictionary of input values required by the agent.
|
|
143
|
+
context (FlockContext, optional): A FlockContext instance to use. If not provided, a default context is used.
|
|
144
|
+
run_id (str, optional): A unique identifier for this run. If empty, one is generated automatically.
|
|
145
|
+
box_result (bool, optional): If True, wraps the output in a Box for nicer formatting. Defaults to True.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
dict: A dictionary containing the result of the agent workflow execution.
|
|
149
|
+
|
|
150
|
+
Raises:
|
|
151
|
+
ValueError: If the specified agent is not found in the registry.
|
|
152
|
+
Exception: For any other errors encountered during execution.
|
|
153
|
+
"""
|
|
154
|
+
try:
|
|
155
|
+
if isinstance(start_agent, str):
|
|
156
|
+
logger.debug("Looking up agent by name", agent_name=start_agent)
|
|
157
|
+
start_agent = self.registry.get_agent(start_agent)
|
|
158
|
+
if not start_agent:
|
|
159
|
+
logger.error("Agent not found", agent_name=start_agent)
|
|
160
|
+
raise ValueError(
|
|
161
|
+
f"Agent '{start_agent}' not found in registry"
|
|
162
|
+
)
|
|
163
|
+
if context:
|
|
164
|
+
logger.debug("Using provided context")
|
|
165
|
+
self.context = context
|
|
166
|
+
if not run_id:
|
|
167
|
+
run_id = f"{start_agent.name}_{uuid.uuid4().hex[:4]}"
|
|
168
|
+
logger.debug("Generated run ID", run_id=run_id)
|
|
169
|
+
|
|
170
|
+
# TODO - Add a check for required input keys
|
|
171
|
+
input_keys = top_level_to_keys(start_agent.input)
|
|
172
|
+
for key in input_keys:
|
|
173
|
+
if key.startswith("flock."):
|
|
174
|
+
key = key[6:] # Remove the "flock." prefix
|
|
175
|
+
if key not in input:
|
|
176
|
+
input[key] = Prompt.ask(
|
|
177
|
+
f"Please enter {key} for {start_agent.name}"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
# Initialize the context with standardized variables
|
|
181
|
+
initialize_context(
|
|
182
|
+
self.context, start_agent.name, input, run_id, self.local_debug
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
logger.info(
|
|
186
|
+
"Starting agent execution",
|
|
187
|
+
agent=start_agent.name,
|
|
188
|
+
local_debug=self.local_debug,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
if self.local_debug:
|
|
192
|
+
return await run_local_workflow(
|
|
193
|
+
self.context, self.output_formatter, box_result
|
|
194
|
+
)
|
|
195
|
+
else:
|
|
196
|
+
return await run_temporal_workflow(self.context, box_result)
|
|
197
|
+
except Exception as e:
|
|
198
|
+
logger.exception("Execution failed", error=str(e))
|
|
199
|
+
raise
|