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.
- flock/__init__.py +1 -4
- flock/core/__init__.py +1 -7
- flock/core/context/context.py +182 -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 +56 -0
- flock/core/flock.py +232 -208
- flock/core/flock_agent.py +574 -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 +141 -0
- flock/core/logging/telemetry.py +21 -0
- flock/core/logging/trace_and_logged.py +55 -0
- flock/core/mixin/dspy_integration.py +197 -0
- flock/core/mixin/prompt_parser.py +125 -0
- flock/core/registry/agent_registry.py +118 -0
- flock/core/tools/basic_tools.py +296 -98
- flock/core/tools/dev_tools/github.py +190 -0
- flock/core/util/cli_helper.py +25 -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 +175 -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.2.dist-info/METADATA +320 -0
- flock_core-0.2.2.dist-info/RECORD +372 -0
- {flock_core-0.1.2.dist-info → flock_core-0.2.2.dist-info}/licenses/LICENSE +21 -21
- flock/agents/__init__.py +0 -3
- flock/agents/batch_agent.py +0 -175
- flock/agents/declarative_agent.py +0 -166
- flock/agents/loop_agent.py +0 -178
- flock/agents/trigger_agent.py +0 -191
- flock/agents/user_agent.py +0 -230
- 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.2.dist-info}/WHEEL +0 -0
flock/app/modules/agent_list.py
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import pathlib
|
|
3
|
-
|
|
4
|
-
from fasthtml.common import *
|
|
5
|
-
from fasthtml.svg import *
|
|
6
|
-
from monsterui.all import *
|
|
7
|
-
|
|
8
|
-
from flock.app.components.util import format_date
|
|
9
|
-
|
|
10
|
-
agent_data = json.load(open(pathlib.Path("data/mock.json")))
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def AgentItem(agent):
|
|
14
|
-
cls_base = "space-y-4 relative rounded-lg border border-border p-3 text-sm hover:bg-primary"
|
|
15
|
-
cls = f"{cls_base} {'bg-muted' if agent == agent_data[0] else ''} {'tag-unread' if not agent['production_ready'] else 'tag-mail'}"
|
|
16
|
-
|
|
17
|
-
return Li(cls=cls)(
|
|
18
|
-
DivFullySpaced(
|
|
19
|
-
DivLAligned(
|
|
20
|
-
Span(UkIcon(agent["icon"]), cls="flex h-10 w-10 items-center justify-center"),
|
|
21
|
-
Div(agent["title"], cls="font-semibold"),
|
|
22
|
-
Span(cls="flex h-2 w-2 rounded-full bg-green-600") if agent["production_ready"] else "",
|
|
23
|
-
),
|
|
24
|
-
Div(format_date(agent["created_at"]), cls="text-xs"),
|
|
25
|
-
cls="mb-4",
|
|
26
|
-
),
|
|
27
|
-
A(agent["name"], cls=TextFont.bold_sm, href=f"#agent-{agent['id']}"),
|
|
28
|
-
Div(agent["description"][:100] + "...", cls=TextFont.muted_sm),
|
|
29
|
-
DivLAligned(*[
|
|
30
|
-
A(label, cls=f"uk-label relative z-10 {'uk-label-primary' if label == 'analysis' else ''}", href="#")
|
|
31
|
-
for label in agent["labels"]
|
|
32
|
-
]),
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def AgentList(agents):
|
|
37
|
-
return Ul(cls="js-filter space-y-4 p-4 pt-0")(*[AgentItem(agent) for agent in agents])
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def AgentContent():
|
|
41
|
-
return Div(cls="flex flex-col", uk_filter="target: .js-filter")(
|
|
42
|
-
Div(cls="flex px-4 py-2 ")(
|
|
43
|
-
H3("Agents"),
|
|
44
|
-
TabContainer(
|
|
45
|
-
Li(A("All Agents", href="#", role="button"), cls="uk-active", uk_filter_control="filter: .tag-mail"),
|
|
46
|
-
Li(A("Production Ready", href="#", role="button"), uk_filter_control="filter: .tag-unread"),
|
|
47
|
-
alt=True,
|
|
48
|
-
cls="ml-auto max-w-80",
|
|
49
|
-
),
|
|
50
|
-
),
|
|
51
|
-
Div(cls="flex flex-1 flex-col")(
|
|
52
|
-
Div(cls="p-4")(
|
|
53
|
-
Div(cls="uk-inline w-full")(
|
|
54
|
-
Span(cls="uk-form-icon text-muted-foreground")(UkIcon("search")), Input(placeholder="Search")
|
|
55
|
-
)
|
|
56
|
-
),
|
|
57
|
-
Div(cls="flex-1 overflow-y-auto max-h-[800px]")(AgentList(agent_data)),
|
|
58
|
-
),
|
|
59
|
-
)
|
flock/app/modules/playground.py
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
from fasthtml.common import *
|
|
2
|
-
from fasthtml.svg import *
|
|
3
|
-
from monsterui.all import *
|
|
4
|
-
|
|
5
|
-
CODE = """
|
|
6
|
-
var pixelSize = 16
|
|
7
|
-
import 'https://cdn.interactjs.io/v1.9.20/auto-start/index.js'
|
|
8
|
-
import 'https://cdn.interactjs.io/v1.9.20/actions/drag/index.js'
|
|
9
|
-
import 'https://cdn.interactjs.io/v1.9.20/actions/resize/index.js'
|
|
10
|
-
import 'https://cdn.interactjs.io/v1.9.20/modifiers/index.js'
|
|
11
|
-
import 'https://cdn.interactjs.io/v1.9.20/dev-tools/index.js'
|
|
12
|
-
import interact from 'https://cdn.interactjs.io/v1.9.20/interactjs/index.js'
|
|
13
|
-
|
|
14
|
-
interact('.rainbow-pixel-canvas')
|
|
15
|
-
.draggable({
|
|
16
|
-
max: Infinity,
|
|
17
|
-
maxPerElement: Infinity,
|
|
18
|
-
origin: 'self',
|
|
19
|
-
modifiers: [
|
|
20
|
-
interact.modifiers.snap({
|
|
21
|
-
// snap to the corners of a grid
|
|
22
|
-
targets: [
|
|
23
|
-
interact.snappers.grid({ x: pixelSize, y: pixelSize })
|
|
24
|
-
]
|
|
25
|
-
})
|
|
26
|
-
],
|
|
27
|
-
listeners: {
|
|
28
|
-
// draw colored squares on move
|
|
29
|
-
move: function (event) {
|
|
30
|
-
var context = event.target.getContext('2d')
|
|
31
|
-
// calculate the angle of the drag direction
|
|
32
|
-
var dragAngle = 180 * Math.atan2(event.dx, event.dy) / Math.PI
|
|
33
|
-
|
|
34
|
-
// set color based on drag angle and speed
|
|
35
|
-
context.fillStyle =
|
|
36
|
-
'hsl(' +
|
|
37
|
-
dragAngle +
|
|
38
|
-
', 86%, ' +
|
|
39
|
-
(30 + Math.min(event.speed / 1000, 1) * 50) +
|
|
40
|
-
'%)'
|
|
41
|
-
|
|
42
|
-
// draw squares
|
|
43
|
-
context.fillRect(
|
|
44
|
-
event.pageX - pixelSize / 2,
|
|
45
|
-
event.pageY - pixelSize / 2,
|
|
46
|
-
pixelSize,
|
|
47
|
-
pixelSize
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
// clear the canvas on doubletap
|
|
53
|
-
.on('doubletap', function (event) {
|
|
54
|
-
var context = event.target.getContext('2d')
|
|
55
|
-
|
|
56
|
-
context.clearRect(0, 0, context.canvas.width, context.canvas.height)
|
|
57
|
-
resizeCanvases()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
function resizeCanvases () {
|
|
61
|
-
[].forEach.call(document.querySelectorAll('.rainbow-pixel-canvas'), function (
|
|
62
|
-
canvas
|
|
63
|
-
) {
|
|
64
|
-
delete canvas.width
|
|
65
|
-
delete canvas.height
|
|
66
|
-
|
|
67
|
-
var rect = canvas.getBoundingClientRect()
|
|
68
|
-
|
|
69
|
-
canvas.width = rect.width
|
|
70
|
-
canvas.height = rect.height
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
resizeCanvases()
|
|
75
|
-
|
|
76
|
-
// interact.js can also add DOM event listeners
|
|
77
|
-
interact(window).on('resize', resizeCanvases)
|
|
78
|
-
"""
|
|
79
|
-
|
|
80
|
-
CODE2 = """
|
|
81
|
-
import 'https://cdn.interactjs.io/v1.9.20/auto-start/index.js'
|
|
82
|
-
import 'https://cdn.interactjs.io/v1.9.20/actions/drag/index.js'
|
|
83
|
-
import 'https://cdn.interactjs.io/v1.9.20/actions/resize/index.js'
|
|
84
|
-
import 'https://cdn.interactjs.io/v1.9.20/modifiers/index.js'
|
|
85
|
-
import 'https://cdn.interactjs.io/v1.9.20/dev-tools/index.js'
|
|
86
|
-
import interact from 'https://cdn.interactjs.io/v1.9.20/interactjs/index.js'
|
|
87
|
-
const svg = document.getElementById('connections');
|
|
88
|
-
|
|
89
|
-
// Function to draw an SVG line between two points
|
|
90
|
-
function createConnectionLine(x1, y1, x2, y2) {
|
|
91
|
-
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
92
|
-
line.setAttribute("x1", x1);
|
|
93
|
-
line.setAttribute("y1", y1);
|
|
94
|
-
line.setAttribute("x2", x2);
|
|
95
|
-
line.setAttribute("y2", y2);
|
|
96
|
-
line.setAttribute("stroke", "red");
|
|
97
|
-
line.setAttribute("stroke-width", "1");
|
|
98
|
-
return line;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Function to update connection lines
|
|
102
|
-
function updateConnections() {
|
|
103
|
-
// Clear existing connections
|
|
104
|
-
svg.innerHTML = '';
|
|
105
|
-
|
|
106
|
-
// Get the positions of the nodes
|
|
107
|
-
const node1 = document.getElementById('node1');
|
|
108
|
-
const node2 = document.getElementById('node2');
|
|
109
|
-
const rect1 = node1.getBoundingClientRect();
|
|
110
|
-
const rect2 = node2.getBoundingClientRect();
|
|
111
|
-
|
|
112
|
-
// Calculate the centers of the nodes
|
|
113
|
-
const x1 = rect1.left + rect1.width / 2;
|
|
114
|
-
const y1 = rect1.top + rect1.height / 2;
|
|
115
|
-
const x2 = rect2.left + rect2.width / 2;
|
|
116
|
-
const y2 = rect2.top + rect2.height / 2;
|
|
117
|
-
|
|
118
|
-
// Create and append a connection line
|
|
119
|
-
const line = createConnectionLine(x1, y1, x2, y2);
|
|
120
|
-
svg.appendChild(line);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Initialize Interact.js
|
|
124
|
-
interact('.node').draggable({
|
|
125
|
-
listeners: {
|
|
126
|
-
move(event) {
|
|
127
|
-
// Move the dragged node
|
|
128
|
-
const target = event.target;
|
|
129
|
-
const x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
|
|
130
|
-
const y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
|
|
131
|
-
|
|
132
|
-
target.style.transform = `translate(${x}px, ${y}px)`;
|
|
133
|
-
target.setAttribute('data-x', x);
|
|
134
|
-
target.setAttribute('data-y', y);
|
|
135
|
-
|
|
136
|
-
// Update the connections
|
|
137
|
-
updateConnections();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// Draw initial connections
|
|
143
|
-
updateConnections();
|
|
144
|
-
"""
|
|
145
|
-
|
|
146
|
-
CODE3 = """
|
|
147
|
-
// Initial data
|
|
148
|
-
let data = {
|
|
149
|
-
nodes: [
|
|
150
|
-
{id: 1, name: "Node 1"},
|
|
151
|
-
{id: 2, name: "Node 2"},
|
|
152
|
-
{id: 3, name: "Node 3"}
|
|
153
|
-
],
|
|
154
|
-
links: [
|
|
155
|
-
{source: 0, target: 1},
|
|
156
|
-
{source: 1, target: 2}
|
|
157
|
-
]
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// Create SVG container
|
|
161
|
-
const svg = d3.select("svg");
|
|
162
|
-
const width = +svg.attr("width");
|
|
163
|
-
const height = +svg.attr("height");
|
|
164
|
-
|
|
165
|
-
// Create force simulation
|
|
166
|
-
const simulation = d3.forceSimulation(data.nodes)
|
|
167
|
-
.force("link", d3.forceLink(data.links).id(d => d.id))
|
|
168
|
-
.force("charge", d3.forceManyBody().strength(-300))
|
|
169
|
-
.force("center", d3.forceCenter(width / 2, height / 2));
|
|
170
|
-
|
|
171
|
-
// Create the links
|
|
172
|
-
const link = svg.append("g")
|
|
173
|
-
.selectAll("line")
|
|
174
|
-
.data(data.links)
|
|
175
|
-
.join("line")
|
|
176
|
-
.attr("class", "link");
|
|
177
|
-
|
|
178
|
-
// Create the nodes
|
|
179
|
-
const node = svg.append("g")
|
|
180
|
-
.selectAll("g")
|
|
181
|
-
.data(data.nodes)
|
|
182
|
-
.join("g")
|
|
183
|
-
.attr("class", "node");
|
|
184
|
-
|
|
185
|
-
// Add circles to nodes
|
|
186
|
-
node.append("circle")
|
|
187
|
-
.attr("r", 10)
|
|
188
|
-
.style("fill", (d, i) => d3.schemeCategory10[i % 10]);
|
|
189
|
-
|
|
190
|
-
// Add labels to nodes
|
|
191
|
-
node.append("text")
|
|
192
|
-
.attr("dx", 12)
|
|
193
|
-
.attr("dy", ".35em")
|
|
194
|
-
.text(d => d.name);
|
|
195
|
-
|
|
196
|
-
// Add drag behavior
|
|
197
|
-
node.call(d3.drag()
|
|
198
|
-
.on("start", dragstarted)
|
|
199
|
-
.on("drag", dragged)
|
|
200
|
-
.on("end", dragended));
|
|
201
|
-
|
|
202
|
-
// Double click on background to add node
|
|
203
|
-
svg.on("dblclick", function(event) {
|
|
204
|
-
const coords = d3.pointer(event);
|
|
205
|
-
const newNode = {
|
|
206
|
-
id: data.nodes.length + 1,
|
|
207
|
-
name: `Node ${data.nodes.length + 1}`,
|
|
208
|
-
x: coords[0],
|
|
209
|
-
y: coords[1]
|
|
210
|
-
};
|
|
211
|
-
data.nodes.push(newNode);
|
|
212
|
-
|
|
213
|
-
// Add link to nearest node
|
|
214
|
-
if (data.nodes.length > 1) {
|
|
215
|
-
const lastNode = data.nodes[data.nodes.length - 2];
|
|
216
|
-
data.links.push({
|
|
217
|
-
source: lastNode,
|
|
218
|
-
target: newNode
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
updateGraph();
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// Update function to refresh the graph
|
|
226
|
-
function updateGraph() {
|
|
227
|
-
// Update links
|
|
228
|
-
const link = svg.selectAll(".link")
|
|
229
|
-
.data(data.links)
|
|
230
|
-
.join("line")
|
|
231
|
-
.attr("class", "link");
|
|
232
|
-
|
|
233
|
-
// Update nodes
|
|
234
|
-
const node = svg.selectAll(".node")
|
|
235
|
-
.data(data.nodes)
|
|
236
|
-
.join(
|
|
237
|
-
enter => {
|
|
238
|
-
const nodeEnter = enter.append("g")
|
|
239
|
-
.attr("class", "node")
|
|
240
|
-
.call(d3.drag()
|
|
241
|
-
.on("start", dragstarted)
|
|
242
|
-
.on("drag", dragged)
|
|
243
|
-
.on("end", dragended));
|
|
244
|
-
|
|
245
|
-
nodeEnter.append("circle")
|
|
246
|
-
.attr("r", 10)
|
|
247
|
-
.style("fill", (d, i) => d3.schemeCategory10[i % 10]);
|
|
248
|
-
|
|
249
|
-
nodeEnter.append("text")
|
|
250
|
-
.attr("dx", 12)
|
|
251
|
-
.attr("dy", ".35em")
|
|
252
|
-
.text(d => d.name);
|
|
253
|
-
|
|
254
|
-
return nodeEnter;
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
// Update simulation
|
|
259
|
-
simulation.nodes(data.nodes);
|
|
260
|
-
simulation.force("link").links(data.links);
|
|
261
|
-
simulation.alpha(1).restart();
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Simulation tick function
|
|
265
|
-
simulation.on("tick", () => {
|
|
266
|
-
link
|
|
267
|
-
.attr("x1", d => d.source.x)
|
|
268
|
-
.attr("y1", d => d.source.y)
|
|
269
|
-
.attr("x2", d => d.target.x)
|
|
270
|
-
.attr("y2", d => d.target.y);
|
|
271
|
-
|
|
272
|
-
node
|
|
273
|
-
.attr("transform", d => `translate(${d.x},${d.y})`);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
// Drag functions
|
|
277
|
-
function dragstarted(event, d) {
|
|
278
|
-
if (!event.active) simulation.alphaTarget(0.3).restart();
|
|
279
|
-
d.fx = d.x;
|
|
280
|
-
d.fy = d.y;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function dragged(event, d) {
|
|
284
|
-
d.fx = event.x;
|
|
285
|
-
d.fy = event.y;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function dragended(event, d) {
|
|
289
|
-
if (!event.active) simulation.alphaTarget(0);
|
|
290
|
-
d.fx = null;
|
|
291
|
-
d.fy = null;
|
|
292
|
-
}
|
|
293
|
-
"""
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def get_playground():
|
|
297
|
-
return Container(
|
|
298
|
-
Canvas(cls="rainbow-pixel-canvas w-full h-full"),
|
|
299
|
-
P("Drag to draw. Double tap to clear."),
|
|
300
|
-
Script(code=CODE, type="module"),
|
|
301
|
-
cls="w-full h-full",
|
|
302
|
-
)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
def get_playground2():
|
|
306
|
-
return Container(
|
|
307
|
-
Svg(
|
|
308
|
-
width="800",
|
|
309
|
-
height="600",
|
|
310
|
-
),
|
|
311
|
-
Script(code=CODE3),
|
|
312
|
-
)
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
def Playground():
|
|
316
|
-
return Div(cls="flex flex-col w-full")(
|
|
317
|
-
Div(cls="px-4 py-2 ")(
|
|
318
|
-
H3("interact.js demo"),
|
|
319
|
-
P("Rainbows!", cls=TextFont.muted_sm),
|
|
320
|
-
),
|
|
321
|
-
get_playground2(),
|
|
322
|
-
)
|
flock/app/modules/settings.py
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"""FrankenUI Forms Example built with MonsterUI (original design by ShadCN)"""
|
|
2
|
-
|
|
3
|
-
from fasthtml.common import *
|
|
4
|
-
from fasthtml.svg import *
|
|
5
|
-
from monsterui.all import *
|
|
6
|
-
|
|
7
|
-
from flock.app.components import ThemeDialog
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def HelpText(c):
|
|
11
|
-
return P(c, cls=TextFont.muted_sm)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def heading():
|
|
15
|
-
return Div(cls="px-4 py-2 ")(
|
|
16
|
-
H3("Settings"),
|
|
17
|
-
P("Manage your account settings and set e-mail preferences.", cls=TextFont.muted_lg),
|
|
18
|
-
DividerSplit(),
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
sidebar_items = ["API Keys", "Appearance", "Display"]
|
|
23
|
-
|
|
24
|
-
sidebar = NavContainer(
|
|
25
|
-
*map(lambda x: Li(A(x)), sidebar_items),
|
|
26
|
-
uk_switcher="connect: #component-nav; animation: uk-animation-fade",
|
|
27
|
-
cls=(NavT.secondary, "space-y-4 p-4 w-1/5"),
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def FormSectionDiv(*c, cls="space-y-2", **kwargs):
|
|
32
|
-
return Div(*c, cls=cls, **kwargs)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def api_key_form():
|
|
36
|
-
content = (
|
|
37
|
-
FormSectionDiv(
|
|
38
|
-
LabelInput("Open AI API Key", placeholder="sk-...", id="username"),
|
|
39
|
-
HelpText("This is your Open AI API key. You can find it in your account settings. "),
|
|
40
|
-
),
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
return UkFormSection("API Keys", "Manage API keys of your agents", button_txt="Update api keys", *content)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def appearance_form():
|
|
47
|
-
content = (
|
|
48
|
-
FormSectionDiv(
|
|
49
|
-
LabelUkSelect(
|
|
50
|
-
*Options("Select a font family", "Inter", "Geist", "Open Sans", selected_idx=2, disabled_idxs={0}),
|
|
51
|
-
label="Font Family",
|
|
52
|
-
id="font_family",
|
|
53
|
-
),
|
|
54
|
-
HelpText("Set the font you want to use in the dashboard."),
|
|
55
|
-
),
|
|
56
|
-
FormSectionDiv(
|
|
57
|
-
FormLabel("Theme"),
|
|
58
|
-
HelpText("Select the theme for the dashboard."),
|
|
59
|
-
ThemeDialog(),
|
|
60
|
-
),
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
return UkFormSection(
|
|
64
|
-
"Appearance",
|
|
65
|
-
"Customize the appearance of the app. Automatically switch between day and night themes.",
|
|
66
|
-
button_txt="Update preferences",
|
|
67
|
-
*content,
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def display_form():
|
|
72
|
-
content = Div(cls="space-y-2")(
|
|
73
|
-
Div(cls="mb-4")(
|
|
74
|
-
Span("Sidebar", cls="text-base font-medium"),
|
|
75
|
-
HelpText("Select the items you want to display in the sidebar."),
|
|
76
|
-
),
|
|
77
|
-
*[
|
|
78
|
-
Div(CheckboxX(id=f"display_{i}", checked=i in [0, 1, 2]), FormLabel(label))
|
|
79
|
-
for i, label in enumerate(["Recents", "Home", "Applications", "Desktop", "Downloads", "Documents"])
|
|
80
|
-
],
|
|
81
|
-
)
|
|
82
|
-
return UkFormSection(
|
|
83
|
-
"Display", "Turn items on or off to control what's displayed in the app.", button_txt="Update display", *content
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def Settings():
|
|
88
|
-
return Title("Settings form"), Container(
|
|
89
|
-
heading(),
|
|
90
|
-
Div(cls="flex gap-x-12")(
|
|
91
|
-
sidebar,
|
|
92
|
-
Ul(id="component-nav", cls="uk-switcher max-w-2xl")(
|
|
93
|
-
Li(cls="uk-active")(api_key_form(), *map(Li, [appearance_form(), display_form()]))
|
|
94
|
-
),
|
|
95
|
-
),
|
|
96
|
-
)
|
flock/core/agent.py
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
from collections.abc import Callable
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
from typing import Any, Literal, TypeVar
|
|
5
|
-
|
|
6
|
-
import cloudpickle
|
|
7
|
-
from pydantic import BaseModel, Field
|
|
8
|
-
|
|
9
|
-
from flock.core.context import FlockContext
|
|
10
|
-
from flock.core.logging import flock_logger, live_update_handler, performance_handler
|
|
11
|
-
from flock.core.serializable import Serializable
|
|
12
|
-
|
|
13
|
-
T = TypeVar("T", bound="Agent")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@dataclass
|
|
17
|
-
class AgentConfig:
|
|
18
|
-
save_to_file: bool = False
|
|
19
|
-
data_type: Literal["json", "cloudpickle", "msgpack"] = "cloudpickle"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class Agent(Serializable, BaseModel, ABC):
|
|
23
|
-
"""Base class for all agents in the framework.
|
|
24
|
-
|
|
25
|
-
Attributes:
|
|
26
|
-
- name: A unique identifier for the agent.
|
|
27
|
-
- model: The model identifier (e.g., an LLM specification).
|
|
28
|
-
- description: A human‑readable description of the agent.
|
|
29
|
-
- hand_off: Defines the next agent to invoke (can be a string or callable).
|
|
30
|
-
- termination: (Optional) A termination condition or phrase; can be used in lifecycle hooks.
|
|
31
|
-
|
|
32
|
-
Lifecycle Hooks:
|
|
33
|
-
- initialize(): Called before the agent runs.
|
|
34
|
-
- terminate(): Called after the agent finishes running.
|
|
35
|
-
|
|
36
|
-
Temporal Execution:
|
|
37
|
-
The default run_temporal() method serializes the agent and the current FlockContext
|
|
38
|
-
and calls a Temporal activity (run_agent_activity) to perform the execution in a Temporal worker.
|
|
39
|
-
Subclasses may override run_temporal() if custom behavior is required.
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
name: str = Field(description="Identifier name for the agent")
|
|
43
|
-
model: str = Field(default="", description="Model of the agent")
|
|
44
|
-
description: str | Callable[..., str] = Field(default="", description="Description of the agent")
|
|
45
|
-
# Use a default factory for hand_off so it defaults to an empty list.
|
|
46
|
-
hand_off: list[str | Callable[..., Any]] = Field(default_factory=list, description="Handoff to another agent")
|
|
47
|
-
termination: str | None = Field(default=None, description="Optional termination condition or phrase")
|
|
48
|
-
|
|
49
|
-
def register(self, registry) -> None:
|
|
50
|
-
"""Register this agent with the provided registry."""
|
|
51
|
-
registry.register_agent(self)
|
|
52
|
-
|
|
53
|
-
@abstractmethod
|
|
54
|
-
async def run(self, context: FlockContext) -> dict:
|
|
55
|
-
"""Execute the agent's logic locally.
|
|
56
|
-
|
|
57
|
-
This method must be implemented by each concrete agent.
|
|
58
|
-
"""
|
|
59
|
-
pass
|
|
60
|
-
|
|
61
|
-
async def run_temporal(self, context: FlockContext) -> dict:
|
|
62
|
-
"""Execute the agent's logic via Temporal."""
|
|
63
|
-
# Run initialization tasks
|
|
64
|
-
await self.initialize(context)
|
|
65
|
-
|
|
66
|
-
from temporalio.client import Client
|
|
67
|
-
|
|
68
|
-
from flock.workflow.agent_activities import run_agent_activity
|
|
69
|
-
from flock.workflow.temporal_setup import run_activity
|
|
70
|
-
|
|
71
|
-
try:
|
|
72
|
-
with performance_handler.track_time("temporal_connection"):
|
|
73
|
-
flock_logger.info("Connecting to Temporal service...")
|
|
74
|
-
client = await Client.connect("localhost:7233", namespace="default")
|
|
75
|
-
|
|
76
|
-
# Convert the FlockContext to a serializable dictionary
|
|
77
|
-
context_data = {
|
|
78
|
-
"state": context.state,
|
|
79
|
-
"history": [record.__dict__ for record in context.history],
|
|
80
|
-
"agent_definitions": [definition.__dict__ for definition in context.agent_definitions],
|
|
81
|
-
}
|
|
82
|
-
agent_data = self.dict()
|
|
83
|
-
|
|
84
|
-
# Execute the Temporal activity
|
|
85
|
-
with performance_handler.track_time("temporal_execution"):
|
|
86
|
-
with live_update_handler.update_workflow_status(self.name, "Running", {"phase": "temporal_activity"}):
|
|
87
|
-
result = await run_activity(
|
|
88
|
-
client,
|
|
89
|
-
self.name,
|
|
90
|
-
run_agent_activity,
|
|
91
|
-
{"agent_data": agent_data, "context_data": context_data},
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
flock_logger.success(f"Temporal activity completed: {self.name}")
|
|
95
|
-
return result
|
|
96
|
-
|
|
97
|
-
except Exception as e:
|
|
98
|
-
flock_logger.error(f"Temporal execution failed: {e}", agent=self.name)
|
|
99
|
-
raise
|
|
100
|
-
finally:
|
|
101
|
-
await self.terminate(context)
|
|
102
|
-
|
|
103
|
-
async def initialize(self, context: FlockContext) -> None:
|
|
104
|
-
"""Lifecycle hook for agent initialization."""
|
|
105
|
-
flock_logger.set_context(workflow_id=context.state.get("workflow_id"))
|
|
106
|
-
flock_logger.info(f"Initializing agent: {self.name}")
|
|
107
|
-
flock_logger.debug("Agent configuration", config=self.dict())
|
|
108
|
-
flock_logger.debug("Context state", state=context.state)
|
|
109
|
-
|
|
110
|
-
async def terminate(self, context: FlockContext) -> None:
|
|
111
|
-
"""Lifecycle hook for agent termination."""
|
|
112
|
-
if self.termination and context.get_variable("init_input") == self.termination:
|
|
113
|
-
flock_logger.warning(
|
|
114
|
-
"Termination condition met",
|
|
115
|
-
condition=self.termination,
|
|
116
|
-
input=context.get_variable("init_input"),
|
|
117
|
-
)
|
|
118
|
-
flock_logger.info(f"Terminating agent: {self.name}")
|
|
119
|
-
|
|
120
|
-
def to_dict(self) -> dict[str, Any]:
|
|
121
|
-
def convert_callable(obj):
|
|
122
|
-
if callable(obj) and not isinstance(obj, type):
|
|
123
|
-
return cloudpickle.dumps(obj).hex() # Serialize functions to hex string
|
|
124
|
-
if isinstance(obj, list):
|
|
125
|
-
return [convert_callable(x) for x in obj]
|
|
126
|
-
if isinstance(obj, dict):
|
|
127
|
-
return {k: convert_callable(v) for k, v in obj.items()}
|
|
128
|
-
return obj
|
|
129
|
-
|
|
130
|
-
# Use Pydantic's model_dump and handle callables
|
|
131
|
-
return convert_callable(self.model_dump())
|
|
132
|
-
|
|
133
|
-
@classmethod
|
|
134
|
-
def from_dict(cls: type[T], data: dict[str, Any]) -> T:
|
|
135
|
-
def convert_callable(obj):
|
|
136
|
-
if isinstance(obj, str) and len(obj) > 2:
|
|
137
|
-
try:
|
|
138
|
-
# Try to deserialize hex string back to callable
|
|
139
|
-
return cloudpickle.loads(bytes.fromhex(obj))
|
|
140
|
-
except:
|
|
141
|
-
return obj
|
|
142
|
-
if isinstance(obj, list):
|
|
143
|
-
return [convert_callable(x) for x in obj]
|
|
144
|
-
if isinstance(obj, dict):
|
|
145
|
-
return {k: convert_callable(v) for k, v in obj.items()}
|
|
146
|
-
return obj
|
|
147
|
-
|
|
148
|
-
# Convert callable strings back to functions
|
|
149
|
-
converted = convert_callable(data)
|
|
150
|
-
return cls(**converted)
|