flock-core 0.1.2__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.2.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.2.dist-info/METADATA +0 -476
- flock_core-0.1.2.dist-info/RECORD +0 -48
- flock_core-0.1.2.dist-info/entry_points.txt +0 -2
- /flock/{core/config/declarative_agent_config.py → workflow/__init__.py} +0 -0
- {flock_core-0.1.2.dist-info → flock_core-0.2.1.dist-info}/WHEEL +0 -0
flock/__init__.py
CHANGED
flock/agents/__init__.py
CHANGED
flock/agents/batch_agent.py
CHANGED
|
@@ -1,175 +1,140 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import uuid
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
|
-
from pydantic import Field
|
|
6
|
-
|
|
7
|
-
from flock.core.context import FlockContext
|
|
8
|
-
from flock.core.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
# Create temporal activity task
|
|
142
|
-
tasks.append(
|
|
143
|
-
run_activity(
|
|
144
|
-
client,
|
|
145
|
-
task_id,
|
|
146
|
-
run_declarative_agent_activity,
|
|
147
|
-
{"agent_data": agent_data, "context_data": context_data},
|
|
148
|
-
)
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
with performance_handler.track_time("temporal_batch_processing"):
|
|
152
|
-
batch_results = await asyncio.gather(*tasks)
|
|
153
|
-
flock_logger.success(f"Completed temporal processing of {num_batches} batches")
|
|
154
|
-
|
|
155
|
-
# Aggregate the outputs
|
|
156
|
-
with performance_handler.track_time("temporal_result_aggregation"):
|
|
157
|
-
flock_logger.info("Aggregating temporal batch results")
|
|
158
|
-
output_keys = self._parse_keys(self.output)
|
|
159
|
-
aggregated = {key: [] for key in output_keys}
|
|
160
|
-
for i, res in enumerate(batch_results):
|
|
161
|
-
flock_logger.debug(f"Aggregating results from temporal batch {i + 1}/{num_batches}")
|
|
162
|
-
for key in output_keys:
|
|
163
|
-
aggregated[key].append(res.get(key))
|
|
164
|
-
aggregated["batch_results"] = batch_results
|
|
165
|
-
flock_logger.success("Successfully aggregated all temporal batch results")
|
|
166
|
-
return aggregated
|
|
167
|
-
|
|
168
|
-
except Exception as e:
|
|
169
|
-
flock_logger.error(
|
|
170
|
-
"Temporal batch processing failed",
|
|
171
|
-
error=str(e),
|
|
172
|
-
agent=self.name,
|
|
173
|
-
iter_input=self.iter_input,
|
|
174
|
-
)
|
|
175
|
-
raise
|
|
1
|
+
import asyncio
|
|
2
|
+
import uuid
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
|
|
7
|
+
from flock.core.context.context import FlockContext
|
|
8
|
+
from flock.core.flock_agent import FlockAgent
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class BatchAgent(FlockAgent):
|
|
12
|
+
"""A DeclarativeAgent that processes an iterable input in batches.
|
|
13
|
+
|
|
14
|
+
Additional Attributes:
|
|
15
|
+
iter_input: The key in the FlockContext that holds the iterable (a list).
|
|
16
|
+
batch_site: The number of items per batch.
|
|
17
|
+
|
|
18
|
+
For each batch, the agent's input dictionary is built from the FlockContext with the
|
|
19
|
+
value for the iter_input key overridden by the current batch. The outputs across batches
|
|
20
|
+
are then aggregated.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
iter_input: str = Field(
|
|
24
|
+
default="",
|
|
25
|
+
description="Key of the iterable input (must be a list in the FlockContext)",
|
|
26
|
+
)
|
|
27
|
+
batch_size: int = Field(
|
|
28
|
+
default=1, description="Batch size (number of items per batch)"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
async def run(self, context: FlockContext) -> dict:
|
|
32
|
+
"""Run the BatchAgent locally by partitioning the iterable and aggregating the results."""
|
|
33
|
+
try:
|
|
34
|
+
iterable = context.get_variable(self.iter_input)
|
|
35
|
+
if not isinstance(iterable, list):
|
|
36
|
+
error_msg = (
|
|
37
|
+
f"Expected a list for key '{self.iter_input}' in context."
|
|
38
|
+
)
|
|
39
|
+
return {"error": error_msg}
|
|
40
|
+
|
|
41
|
+
# Partition the iterable into batches
|
|
42
|
+
batches: list[list[Any]] = [
|
|
43
|
+
iterable[i : i + self.batch_size]
|
|
44
|
+
for i in range(0, len(iterable), self.batch_size)
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
# Process batches
|
|
48
|
+
tasks = []
|
|
49
|
+
for batch in batches:
|
|
50
|
+
tasks.append(
|
|
51
|
+
self.evaluate(
|
|
52
|
+
context, input_overrides={self.iter_input: batch}
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
batch_results = await asyncio.gather(*tasks)
|
|
57
|
+
|
|
58
|
+
# Aggregate the outputs
|
|
59
|
+
output_keys = self._parse_keys(self.output)
|
|
60
|
+
aggregated = {key: [] for key in output_keys}
|
|
61
|
+
for res in batch_results:
|
|
62
|
+
for key in output_keys:
|
|
63
|
+
aggregated[key].append(res.get(key))
|
|
64
|
+
aggregated["batch_results"] = batch_results
|
|
65
|
+
return aggregated
|
|
66
|
+
|
|
67
|
+
except Exception:
|
|
68
|
+
raise
|
|
69
|
+
|
|
70
|
+
async def run_temporal(self, context: FlockContext) -> dict:
|
|
71
|
+
"""Run the BatchAgent via Temporal.
|
|
72
|
+
|
|
73
|
+
For each batch, the agent's evaluation is performed as a separate Temporal activity.
|
|
74
|
+
The results are then aggregated.
|
|
75
|
+
"""
|
|
76
|
+
try:
|
|
77
|
+
from temporalio.client import Client
|
|
78
|
+
|
|
79
|
+
from flock.workflow.agent_activities import (
|
|
80
|
+
run_declarative_agent_activity,
|
|
81
|
+
)
|
|
82
|
+
from flock.workflow.temporal_setup import run_activity
|
|
83
|
+
|
|
84
|
+
# Connect to Temporal
|
|
85
|
+
client = await Client.connect("localhost:7233", namespace="default")
|
|
86
|
+
|
|
87
|
+
# Validate and prepare input
|
|
88
|
+
iterable = context.get_variable(self.iter_input)
|
|
89
|
+
if not isinstance(iterable, list):
|
|
90
|
+
error_msg = (
|
|
91
|
+
f"Expected a list for key '{self.iter_input}' in context."
|
|
92
|
+
)
|
|
93
|
+
return {"error": error_msg}
|
|
94
|
+
|
|
95
|
+
# Partition into batches
|
|
96
|
+
batches: list[list[Any]] = [
|
|
97
|
+
iterable[i : i + self.batch_size]
|
|
98
|
+
for i in range(0, len(iterable), self.batch_size)
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
# Process batches
|
|
102
|
+
tasks = []
|
|
103
|
+
for batch in batches:
|
|
104
|
+
# Prepare context for this batch
|
|
105
|
+
new_state = context.state.copy()
|
|
106
|
+
new_state[self.iter_input] = batch
|
|
107
|
+
context_data = {
|
|
108
|
+
"state": new_state,
|
|
109
|
+
"history": [], # you might choose to pass along history if needed
|
|
110
|
+
"agent_definitions": [],
|
|
111
|
+
}
|
|
112
|
+
agent_data = self.dict()
|
|
113
|
+
task_id = f"{self.name}_{uuid.uuid4().hex[:4]}"
|
|
114
|
+
|
|
115
|
+
# Create temporal activity task
|
|
116
|
+
tasks.append(
|
|
117
|
+
run_activity(
|
|
118
|
+
client,
|
|
119
|
+
task_id,
|
|
120
|
+
run_declarative_agent_activity,
|
|
121
|
+
{
|
|
122
|
+
"agent_data": agent_data,
|
|
123
|
+
"context_data": context_data,
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
batch_results = await asyncio.gather(*tasks)
|
|
129
|
+
|
|
130
|
+
# Aggregate the outputs
|
|
131
|
+
output_keys = self._parse_keys(self.output)
|
|
132
|
+
aggregated = {key: [] for key in output_keys}
|
|
133
|
+
for res in batch_results:
|
|
134
|
+
for key in output_keys:
|
|
135
|
+
aggregated[key].append(res.get(key))
|
|
136
|
+
aggregated["batch_results"] = batch_results
|
|
137
|
+
return aggregated
|
|
138
|
+
|
|
139
|
+
except Exception:
|
|
140
|
+
raise
|
flock/agents/loop_agent.py
CHANGED
|
@@ -1,178 +1,117 @@
|
|
|
1
|
-
from collections.abc import Callable
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
from pydantic import Field
|
|
5
|
-
|
|
6
|
-
from flock.core.
|
|
7
|
-
from flock.core.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
"""Run the loop agent via Temporal."""
|
|
119
|
-
try:
|
|
120
|
-
from temporalio.client import Client
|
|
121
|
-
|
|
122
|
-
from flock.workflow.agent_activities import run_agent_activity
|
|
123
|
-
from flock.workflow.temporal_setup import run_activity
|
|
124
|
-
|
|
125
|
-
with performance_handler.track_time("temporal_setup"):
|
|
126
|
-
flock_logger.info(f"Starting temporal loop agent: {self.name}")
|
|
127
|
-
client = await Client.connect("localhost:7233", namespace="default")
|
|
128
|
-
|
|
129
|
-
results = []
|
|
130
|
-
iteration = 0
|
|
131
|
-
|
|
132
|
-
with live_update_handler.update_workflow_status(
|
|
133
|
-
self.name, "Running", {"phase": "loop_execution", "max_iterations": self.max_iterations}
|
|
134
|
-
):
|
|
135
|
-
while True:
|
|
136
|
-
# Process iteration as a temporal activity
|
|
137
|
-
with performance_handler.track_time(f"temporal_iteration_{iteration}"):
|
|
138
|
-
context_data = {
|
|
139
|
-
"state": context.state,
|
|
140
|
-
"history": [record.__dict__ for record in context.history],
|
|
141
|
-
"agent_definitions": [definition.__dict__ for definition in context.agent_definitions],
|
|
142
|
-
}
|
|
143
|
-
agent_data = self.dict()
|
|
144
|
-
|
|
145
|
-
flock_logger.info(f"Starting temporal iteration {iteration + 1}")
|
|
146
|
-
result = await run_activity(
|
|
147
|
-
client,
|
|
148
|
-
f"{self.name}_iteration_{iteration}",
|
|
149
|
-
run_agent_activity,
|
|
150
|
-
{"agent_data": agent_data, "context_data": context_data},
|
|
151
|
-
)
|
|
152
|
-
results.append(result)
|
|
153
|
-
|
|
154
|
-
# Check termination conditions
|
|
155
|
-
if not self._should_continue(result, iteration):
|
|
156
|
-
break
|
|
157
|
-
|
|
158
|
-
iteration += 1
|
|
159
|
-
|
|
160
|
-
flock_logger.success(
|
|
161
|
-
"Temporal loop completed successfully",
|
|
162
|
-
total_iterations=iteration + 1,
|
|
163
|
-
agent=self.name,
|
|
164
|
-
)
|
|
165
|
-
return {
|
|
166
|
-
"iterations": iteration + 1,
|
|
167
|
-
"results": results,
|
|
168
|
-
"final_result": results[-1] if results else None,
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
except Exception as e:
|
|
172
|
-
flock_logger.error(
|
|
173
|
-
"Temporal loop execution failed",
|
|
174
|
-
error=str(e),
|
|
175
|
-
agent=self.name,
|
|
176
|
-
iteration=iteration,
|
|
177
|
-
)
|
|
178
|
-
raise
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from pydantic import Field
|
|
5
|
+
|
|
6
|
+
from flock.core.context.context import FlockContext
|
|
7
|
+
from flock.core.flock_agent import FlockAgent
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LoopAgent(FlockAgent):
|
|
11
|
+
"""An agent that executes its logic in a loop until a termination condition is met.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
input: Input domain for the agent
|
|
15
|
+
output: Output types for the agent
|
|
16
|
+
tools: Tools the agent is allowed to use
|
|
17
|
+
max_iterations: Maximum number of iterations before forced termination
|
|
18
|
+
termination_condition: Optional callable that determines when to stop the loop
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
input: str = Field(default="", description="Input domain for the agent")
|
|
22
|
+
output: str = Field(default="", description="Output types for the agent")
|
|
23
|
+
tools: list[Callable] | None = Field(default=None, description="Tools the agent is allowed to use")
|
|
24
|
+
max_iterations: int = Field(default=10, description="Maximum number of iterations")
|
|
25
|
+
termination_condition: Callable[[dict[str, Any]], bool] | None = Field(
|
|
26
|
+
default=None, description="Optional function to determine loop termination"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
async def _process_iteration(self, context: FlockContext, iteration: int) -> dict[str, Any]:
|
|
30
|
+
"""Process a single iteration of the loop."""
|
|
31
|
+
try:
|
|
32
|
+
# Here you would implement the actual iteration logic
|
|
33
|
+
# For now, we'll just return a simple result
|
|
34
|
+
return {"iteration": iteration, "status": "completed"}
|
|
35
|
+
except Exception:
|
|
36
|
+
raise
|
|
37
|
+
|
|
38
|
+
def _should_continue(self, result: dict[str, Any], iteration: int) -> bool:
|
|
39
|
+
"""Determine if the loop should continue."""
|
|
40
|
+
if iteration >= self.max_iterations:
|
|
41
|
+
return False
|
|
42
|
+
|
|
43
|
+
if self.termination_condition:
|
|
44
|
+
should_terminate = self.termination_condition(result)
|
|
45
|
+
return not should_terminate
|
|
46
|
+
|
|
47
|
+
return True
|
|
48
|
+
|
|
49
|
+
async def run(self, context: FlockContext) -> dict[str, Any]:
|
|
50
|
+
"""Run the agent in a loop until the termination condition is met or max iterations reached."""
|
|
51
|
+
try:
|
|
52
|
+
results = []
|
|
53
|
+
iteration = 0
|
|
54
|
+
|
|
55
|
+
while True:
|
|
56
|
+
result = await self._process_iteration(context, iteration)
|
|
57
|
+
results.append(result)
|
|
58
|
+
|
|
59
|
+
# Check termination conditions
|
|
60
|
+
if not self._should_continue(result, iteration):
|
|
61
|
+
break
|
|
62
|
+
|
|
63
|
+
iteration += 1
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
"iterations": iteration + 1,
|
|
67
|
+
"results": results,
|
|
68
|
+
"final_result": results[-1] if results else None,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
except Exception:
|
|
72
|
+
raise
|
|
73
|
+
|
|
74
|
+
async def run_temporal(self, context: FlockContext) -> dict[str, Any]:
|
|
75
|
+
"""Run the loop agent via Temporal."""
|
|
76
|
+
try:
|
|
77
|
+
from temporalio.client import Client
|
|
78
|
+
|
|
79
|
+
from flock.workflow.agent_activities import run_agent_activity
|
|
80
|
+
from flock.workflow.temporal_setup import run_activity
|
|
81
|
+
|
|
82
|
+
client = await Client.connect("localhost:7233", namespace="default")
|
|
83
|
+
|
|
84
|
+
results = []
|
|
85
|
+
iteration = 0
|
|
86
|
+
|
|
87
|
+
while True:
|
|
88
|
+
# Process iteration as a temporal activity
|
|
89
|
+
context_data = {
|
|
90
|
+
"state": context.state,
|
|
91
|
+
"history": [record.__dict__ for record in context.history],
|
|
92
|
+
"agent_definitions": [definition.__dict__ for definition in context.agent_definitions],
|
|
93
|
+
}
|
|
94
|
+
agent_data = self.dict()
|
|
95
|
+
|
|
96
|
+
result = await run_activity(
|
|
97
|
+
client,
|
|
98
|
+
f"{self.name}_iteration_{iteration}",
|
|
99
|
+
run_agent_activity,
|
|
100
|
+
{"agent_data": agent_data, "context_data": context_data},
|
|
101
|
+
)
|
|
102
|
+
results.append(result)
|
|
103
|
+
|
|
104
|
+
# Check termination conditions
|
|
105
|
+
if not self._should_continue(result, iteration):
|
|
106
|
+
break
|
|
107
|
+
|
|
108
|
+
iteration += 1
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
"iterations": iteration + 1,
|
|
112
|
+
"results": results,
|
|
113
|
+
"final_result": results[-1] if results else None,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
except Exception:
|
|
117
|
+
raise
|