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/core/agent_registry.py
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
from collections.abc import Callable
|
|
2
|
-
|
|
3
|
-
from flock.core.agent import Agent
|
|
4
|
-
from flock.core.logging import flock_logger, performance_handler
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class Registry:
|
|
8
|
-
"""Registry for storing and managing agents and tools.
|
|
9
|
-
|
|
10
|
-
This singleton class maintains a centralized registry of agents and tools,
|
|
11
|
-
which is particularly important for Temporal workflows where only basic Python
|
|
12
|
-
types can be passed between activities.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
_instance = None
|
|
16
|
-
|
|
17
|
-
def __new__(cls):
|
|
18
|
-
"""Singleton pattern implementation."""
|
|
19
|
-
if cls._instance is None:
|
|
20
|
-
cls._instance = super().__new__(cls)
|
|
21
|
-
with performance_handler.track_time("registry_initialization"):
|
|
22
|
-
flock_logger.info("Initializing new Registry instance")
|
|
23
|
-
cls._instance._initialize()
|
|
24
|
-
return cls._instance
|
|
25
|
-
|
|
26
|
-
def _initialize(self):
|
|
27
|
-
"""Initialize the registry's storage."""
|
|
28
|
-
self._agents: list[Agent] = []
|
|
29
|
-
self._tools: list[tuple[str, Callable]] = []
|
|
30
|
-
flock_logger.debug("Registry storage initialized")
|
|
31
|
-
|
|
32
|
-
def register_tool(self, tool_name: str, tool: Callable) -> None:
|
|
33
|
-
"""Register a tool with the registry.
|
|
34
|
-
|
|
35
|
-
Args:
|
|
36
|
-
tool_name: The name to register the tool under
|
|
37
|
-
tool: The tool function to register
|
|
38
|
-
"""
|
|
39
|
-
try:
|
|
40
|
-
with performance_handler.track_time("tool_registration"):
|
|
41
|
-
self._tools.append((tool_name, tool))
|
|
42
|
-
flock_logger.info(f"Registered tool: {tool_name}")
|
|
43
|
-
flock_logger.debug("Tool details", tool_name=tool_name, tool_type=type(tool).__name__)
|
|
44
|
-
except Exception as e:
|
|
45
|
-
flock_logger.error(
|
|
46
|
-
"Tool registration failed",
|
|
47
|
-
tool_name=tool_name,
|
|
48
|
-
error=str(e),
|
|
49
|
-
)
|
|
50
|
-
raise
|
|
51
|
-
|
|
52
|
-
def register_agent(self, agent: Agent) -> None:
|
|
53
|
-
"""Register an agent with the registry.
|
|
54
|
-
|
|
55
|
-
Args:
|
|
56
|
-
agent: The agent instance to register
|
|
57
|
-
"""
|
|
58
|
-
try:
|
|
59
|
-
with performance_handler.track_time("agent_registration"):
|
|
60
|
-
self._agents.append(agent)
|
|
61
|
-
flock_logger.info(f"Registered agent: {agent.name}")
|
|
62
|
-
flock_logger.debug(
|
|
63
|
-
"Agent details",
|
|
64
|
-
name=agent.name,
|
|
65
|
-
type=type(agent).__name__,
|
|
66
|
-
model=agent.model,
|
|
67
|
-
)
|
|
68
|
-
except Exception as e:
|
|
69
|
-
flock_logger.error(
|
|
70
|
-
"Agent registration failed",
|
|
71
|
-
agent_name=getattr(agent, "name", "unknown"),
|
|
72
|
-
error=str(e),
|
|
73
|
-
)
|
|
74
|
-
raise
|
|
75
|
-
|
|
76
|
-
def get_agent(self, name: str) -> Agent | None:
|
|
77
|
-
"""Retrieve an agent by name.
|
|
78
|
-
|
|
79
|
-
Args:
|
|
80
|
-
name: The name of the agent to retrieve
|
|
81
|
-
|
|
82
|
-
Returns:
|
|
83
|
-
The agent instance if found, None otherwise
|
|
84
|
-
"""
|
|
85
|
-
try:
|
|
86
|
-
with performance_handler.track_time("agent_retrieval"):
|
|
87
|
-
for agent in self._agents:
|
|
88
|
-
if agent.name == name:
|
|
89
|
-
flock_logger.debug(f"Retrieved agent: {name}")
|
|
90
|
-
return agent
|
|
91
|
-
|
|
92
|
-
flock_logger.warning(f"Agent not found: {name}")
|
|
93
|
-
return None
|
|
94
|
-
except Exception as e:
|
|
95
|
-
flock_logger.error(
|
|
96
|
-
"Agent retrieval failed",
|
|
97
|
-
agent_name=name,
|
|
98
|
-
error=str(e),
|
|
99
|
-
)
|
|
100
|
-
raise
|
|
101
|
-
|
|
102
|
-
def get_tool(self, name: str) -> Callable | None:
|
|
103
|
-
"""Retrieve a tool by name.
|
|
104
|
-
|
|
105
|
-
Args:
|
|
106
|
-
name: The name of the tool to retrieve
|
|
107
|
-
|
|
108
|
-
Returns:
|
|
109
|
-
The tool function if found, None otherwise
|
|
110
|
-
"""
|
|
111
|
-
try:
|
|
112
|
-
with performance_handler.track_time("tool_retrieval"):
|
|
113
|
-
for tool_name, tool in self._tools:
|
|
114
|
-
if tool_name == name:
|
|
115
|
-
flock_logger.debug(f"Retrieved tool: {name}")
|
|
116
|
-
return tool
|
|
117
|
-
|
|
118
|
-
flock_logger.warning(f"Tool not found: {name}")
|
|
119
|
-
return None
|
|
120
|
-
except Exception as e:
|
|
121
|
-
flock_logger.error(
|
|
122
|
-
"Tool retrieval failed",
|
|
123
|
-
tool_name=name,
|
|
124
|
-
error=str(e),
|
|
125
|
-
)
|
|
126
|
-
raise
|
|
127
|
-
|
|
128
|
-
def get_tools(self, names: list[str] | None) -> list[Callable]:
|
|
129
|
-
"""Retrieve multiple tools by name.
|
|
130
|
-
|
|
131
|
-
Args:
|
|
132
|
-
names: List of tool names to retrieve
|
|
133
|
-
|
|
134
|
-
Returns:
|
|
135
|
-
List of found tool functions (may be empty if none found)
|
|
136
|
-
"""
|
|
137
|
-
try:
|
|
138
|
-
with performance_handler.track_time("tools_retrieval"):
|
|
139
|
-
if not names:
|
|
140
|
-
flock_logger.debug("No tool names provided")
|
|
141
|
-
return []
|
|
142
|
-
|
|
143
|
-
tools = [self.get_tool(name) for name in names]
|
|
144
|
-
found_tools = [name for name, tool in zip(names, tools) if tool is not None]
|
|
145
|
-
|
|
146
|
-
if found_tools:
|
|
147
|
-
flock_logger.debug(
|
|
148
|
-
"Retrieved tools",
|
|
149
|
-
requested=len(names),
|
|
150
|
-
found=len(found_tools),
|
|
151
|
-
)
|
|
152
|
-
return [tool for tool in tools if tool is not None]
|
|
153
|
-
|
|
154
|
-
flock_logger.warning("No tools found", requested=names)
|
|
155
|
-
return []
|
|
156
|
-
except Exception as e:
|
|
157
|
-
flock_logger.error(
|
|
158
|
-
"Tools retrieval failed",
|
|
159
|
-
tool_names=names,
|
|
160
|
-
error=str(e),
|
|
161
|
-
)
|
|
162
|
-
raise
|
flock/core/context.py
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
from dataclasses import asdict, dataclass, field
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
from typing import Any, Literal
|
|
4
|
-
|
|
5
|
-
from flock.core.context_vars import FLOCK_LAST_AGENT, FLOCK_LAST_RESULT
|
|
6
|
-
from flock.core.logging import flock_logger, performance_handler
|
|
7
|
-
from flock.core.serializable import Serializable
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@dataclass
|
|
11
|
-
class AgentRunRecord:
|
|
12
|
-
agent: str = field(default="") # Agent name
|
|
13
|
-
input_data: dict[str, Any] = field(default_factory=dict)
|
|
14
|
-
output_data: dict[str, Any] = field(default_factory=dict)
|
|
15
|
-
timestamp: str = field(default="")
|
|
16
|
-
hand_off: str = field(default="") # Next agent name
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@dataclass
|
|
20
|
-
class AgentDefinition:
|
|
21
|
-
agent_type: str = field(default="")
|
|
22
|
-
agent_name: str = field(default="")
|
|
23
|
-
agent_data: dict = field(default=dict)
|
|
24
|
-
serializer: Literal["json", "cloudpickle", "msgpack"] = field(default="cloudpickle")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@dataclass
|
|
28
|
-
class FlockContext(Serializable):
|
|
29
|
-
state: dict[str, Any] = field(default_factory=dict)
|
|
30
|
-
history: list[AgentRunRecord] = field(default_factory=list)
|
|
31
|
-
agent_definitions: dict[str, AgentDefinition] = field(default_factory=dict)
|
|
32
|
-
run_id: str = field(default="")
|
|
33
|
-
workflow_id: str = field(default="")
|
|
34
|
-
workflow_timestamp: str = field(default="")
|
|
35
|
-
|
|
36
|
-
def record(self, agent_name: str, data: dict[str, Any], timestamp: str, hand_off: str) -> None:
|
|
37
|
-
"""Record an agent run and update the state with the agent's output."""
|
|
38
|
-
try:
|
|
39
|
-
with performance_handler.track_time("record_agent_run"):
|
|
40
|
-
flock_logger.info(f"Recording agent run: {agent_name}")
|
|
41
|
-
record = AgentRunRecord(
|
|
42
|
-
agent=agent_name, output_data=data.copy(), timestamp=timestamp, hand_off=hand_off
|
|
43
|
-
)
|
|
44
|
-
self.history.append(record)
|
|
45
|
-
flock_logger.debug(
|
|
46
|
-
"Created run record",
|
|
47
|
-
agent=agent_name,
|
|
48
|
-
output_keys=list(data.keys()),
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
self.set_variable(f"{agent_name}.result", data)
|
|
52
|
-
self.set_variable(FLOCK_LAST_RESULT, data)
|
|
53
|
-
self.set_variable(FLOCK_LAST_AGENT, agent_name)
|
|
54
|
-
flock_logger.debug("Updated context state with agent output")
|
|
55
|
-
|
|
56
|
-
except Exception as e:
|
|
57
|
-
flock_logger.error(
|
|
58
|
-
"Failed to record agent run",
|
|
59
|
-
agent=agent_name,
|
|
60
|
-
error=str(e),
|
|
61
|
-
)
|
|
62
|
-
raise
|
|
63
|
-
|
|
64
|
-
def get_variable(self, key: str) -> Any:
|
|
65
|
-
"""Get the current value of a state variable."""
|
|
66
|
-
try:
|
|
67
|
-
with performance_handler.track_time("get_variable"):
|
|
68
|
-
value = self.state.get(key)
|
|
69
|
-
if value is None:
|
|
70
|
-
flock_logger.warning(f"Variable not found in state: {key}")
|
|
71
|
-
else:
|
|
72
|
-
flock_logger.debug(f"Retrieved variable: {key}")
|
|
73
|
-
return value
|
|
74
|
-
except Exception as e:
|
|
75
|
-
flock_logger.error(
|
|
76
|
-
"Failed to get variable",
|
|
77
|
-
key=key,
|
|
78
|
-
error=str(e),
|
|
79
|
-
)
|
|
80
|
-
raise
|
|
81
|
-
|
|
82
|
-
def set_variable(self, key: str, value: Any) -> None:
|
|
83
|
-
"""Set the value of a state variable."""
|
|
84
|
-
try:
|
|
85
|
-
with performance_handler.track_time("set_variable"):
|
|
86
|
-
self.state[key] = value
|
|
87
|
-
flock_logger.debug(f"Set variable: {key}")
|
|
88
|
-
except Exception as e:
|
|
89
|
-
flock_logger.error(
|
|
90
|
-
"Failed to set variable",
|
|
91
|
-
key=key,
|
|
92
|
-
error=str(e),
|
|
93
|
-
)
|
|
94
|
-
raise
|
|
95
|
-
|
|
96
|
-
def deepcopy(self) -> "FlockContext":
|
|
97
|
-
"""Create a deep copy of the context."""
|
|
98
|
-
try:
|
|
99
|
-
with performance_handler.track_time("context_deepcopy"):
|
|
100
|
-
flock_logger.debug("Creating deep copy of context")
|
|
101
|
-
copy = FlockContext.from_dict(self.to_dict())
|
|
102
|
-
flock_logger.debug(
|
|
103
|
-
"Context copied",
|
|
104
|
-
state_vars=len(copy.state),
|
|
105
|
-
history_records=len(copy.history),
|
|
106
|
-
)
|
|
107
|
-
return copy
|
|
108
|
-
except Exception as e:
|
|
109
|
-
flock_logger.error(
|
|
110
|
-
"Failed to create context copy",
|
|
111
|
-
error=str(e),
|
|
112
|
-
)
|
|
113
|
-
raise
|
|
114
|
-
|
|
115
|
-
def get_agent_history(self, agent_name: str) -> list[AgentRunRecord]:
|
|
116
|
-
"""Return all agent run records for a given agent name."""
|
|
117
|
-
try:
|
|
118
|
-
with performance_handler.track_time("get_agent_history"):
|
|
119
|
-
records = [record for record in self.history if record.agent == agent_name]
|
|
120
|
-
flock_logger.debug(
|
|
121
|
-
f"Retrieved history records for {agent_name}",
|
|
122
|
-
count=len(records),
|
|
123
|
-
)
|
|
124
|
-
return records
|
|
125
|
-
except Exception as e:
|
|
126
|
-
flock_logger.error(
|
|
127
|
-
"Failed to get history records",
|
|
128
|
-
agent=agent_name,
|
|
129
|
-
error=str(e),
|
|
130
|
-
)
|
|
131
|
-
raise
|
|
132
|
-
|
|
133
|
-
def next_input_for(self, agent) -> Any:
|
|
134
|
-
"""By default, the next input for an agent is taken from the context state.
|
|
135
|
-
|
|
136
|
-
If the agent.input is a comma-separated list (e.g., "input1, input2"),
|
|
137
|
-
this method will return a dictionary with keys for each of the input names,
|
|
138
|
-
fetching the latest values from the state.
|
|
139
|
-
|
|
140
|
-
If only a single input is specified, the raw value is returned.
|
|
141
|
-
"""
|
|
142
|
-
try:
|
|
143
|
-
with performance_handler.track_time("next_input_preparation"):
|
|
144
|
-
flock_logger.info(f"Preparing next input for agent: {agent.name}")
|
|
145
|
-
|
|
146
|
-
if hasattr(agent, "input") and isinstance(agent.input, str):
|
|
147
|
-
keys = [k.strip() for k in agent.input.split(",") if k.strip()]
|
|
148
|
-
flock_logger.debug(f"Input keys: {keys}")
|
|
149
|
-
|
|
150
|
-
if len(keys) == 1:
|
|
151
|
-
value = self.get_variable(keys[0])
|
|
152
|
-
flock_logger.debug(f"Single input value retrieved for key: {keys[0]}")
|
|
153
|
-
return value
|
|
154
|
-
else:
|
|
155
|
-
values = {key: self.get_variable(key) for key in keys}
|
|
156
|
-
flock_logger.debug(f"Multiple input values retrieved for keys: {keys}")
|
|
157
|
-
return values
|
|
158
|
-
else:
|
|
159
|
-
# Fallback to "init_input"
|
|
160
|
-
flock_logger.debug("No input defined, falling back to init_input")
|
|
161
|
-
return self.get_variable("init_input")
|
|
162
|
-
except Exception as e:
|
|
163
|
-
flock_logger.error(
|
|
164
|
-
"Failed to prepare next input",
|
|
165
|
-
agent=getattr(agent, "name", str(agent)),
|
|
166
|
-
error=str(e),
|
|
167
|
-
)
|
|
168
|
-
raise
|
|
169
|
-
|
|
170
|
-
def get_agent_definition(self, agent_name: str) -> AgentDefinition | None:
|
|
171
|
-
"""Get the definition for a specific agent."""
|
|
172
|
-
try:
|
|
173
|
-
with performance_handler.track_time("get_agent_definition"):
|
|
174
|
-
for definition in self.agent_definitions:
|
|
175
|
-
if definition.name == agent_name:
|
|
176
|
-
flock_logger.debug(f"Retrieved definition for agent: {agent_name}")
|
|
177
|
-
return definition
|
|
178
|
-
|
|
179
|
-
flock_logger.warning(f"No definition found for agent: {agent_name}")
|
|
180
|
-
return None
|
|
181
|
-
except Exception as e:
|
|
182
|
-
flock_logger.error(
|
|
183
|
-
"Failed to get agent definition",
|
|
184
|
-
agent=agent_name,
|
|
185
|
-
error=str(e),
|
|
186
|
-
)
|
|
187
|
-
raise
|
|
188
|
-
|
|
189
|
-
def add_agent_definition(self, agent_type: type, agent_name: str, agent_data: Any) -> None:
|
|
190
|
-
"""Add a new agent definition to the context."""
|
|
191
|
-
try:
|
|
192
|
-
with performance_handler.track_time("add_agent_definition"):
|
|
193
|
-
definition = AgentDefinition(
|
|
194
|
-
agent_type=agent_type.__name__,
|
|
195
|
-
agent_name=agent_name,
|
|
196
|
-
agent_data=agent_data,
|
|
197
|
-
)
|
|
198
|
-
self.agent_definitions[agent_name] = definition
|
|
199
|
-
flock_logger.info(
|
|
200
|
-
f"Added agent definition",
|
|
201
|
-
agent=agent_name,
|
|
202
|
-
type=agent_type.__name__,
|
|
203
|
-
)
|
|
204
|
-
except Exception as e:
|
|
205
|
-
flock_logger.error(
|
|
206
|
-
"Failed to add agent definition",
|
|
207
|
-
agent=agent_name,
|
|
208
|
-
type=agent_type.__name__,
|
|
209
|
-
error=str(e),
|
|
210
|
-
)
|
|
211
|
-
raise
|
|
212
|
-
|
|
213
|
-
# Allow dict-like access for convenience.
|
|
214
|
-
def __getitem__(self, key: str) -> Any:
|
|
215
|
-
value = self.state[key]
|
|
216
|
-
return value
|
|
217
|
-
|
|
218
|
-
def __setitem__(self, key: str, value: Any) -> None:
|
|
219
|
-
self.state[key] = value
|
|
220
|
-
|
|
221
|
-
def to_dict(self) -> dict[str, Any]:
|
|
222
|
-
"""Convert the context to a dictionary for serialization."""
|
|
223
|
-
try:
|
|
224
|
-
with performance_handler.track_time("context_to_dict"):
|
|
225
|
-
flock_logger.debug("Converting context to dictionary")
|
|
226
|
-
|
|
227
|
-
def convert(obj):
|
|
228
|
-
if isinstance(obj, datetime):
|
|
229
|
-
return obj.isoformat()
|
|
230
|
-
if hasattr(obj, "__dataclass_fields__"): # Is a dataclass
|
|
231
|
-
return asdict(obj, dict_factory=lambda x: {k: convert(v) for k, v in x})
|
|
232
|
-
return obj
|
|
233
|
-
|
|
234
|
-
result = convert(asdict(self))
|
|
235
|
-
flock_logger.debug(
|
|
236
|
-
"Context converted to dictionary",
|
|
237
|
-
state_size=len(result.get("state", {})),
|
|
238
|
-
history_size=len(result.get("history", [])),
|
|
239
|
-
)
|
|
240
|
-
return result
|
|
241
|
-
except Exception as e:
|
|
242
|
-
flock_logger.error(
|
|
243
|
-
"Failed to convert context to dictionary",
|
|
244
|
-
error=str(e),
|
|
245
|
-
)
|
|
246
|
-
raise
|
|
247
|
-
|
|
248
|
-
@classmethod
|
|
249
|
-
def from_dict(cls, data: dict[str, Any]) -> "FlockContext":
|
|
250
|
-
"""Create a context instance from a dictionary."""
|
|
251
|
-
try:
|
|
252
|
-
with performance_handler.track_time("context_from_dict"):
|
|
253
|
-
flock_logger.debug("Creating context from dictionary")
|
|
254
|
-
|
|
255
|
-
def convert(obj):
|
|
256
|
-
if isinstance(obj, dict):
|
|
257
|
-
if "timestamp" in obj: # AgentRunRecord
|
|
258
|
-
return AgentRunRecord(**{**obj, "timestamp": datetime.fromisoformat(obj["timestamp"])})
|
|
259
|
-
if "agent_type" in obj: # AgentDefinition
|
|
260
|
-
return AgentDefinition(**obj)
|
|
261
|
-
return {k: convert(v) for k, v in obj.items()}
|
|
262
|
-
if isinstance(obj, list):
|
|
263
|
-
return [convert(v) for v in obj]
|
|
264
|
-
return obj
|
|
265
|
-
|
|
266
|
-
converted = convert(data)
|
|
267
|
-
context = cls(**converted)
|
|
268
|
-
flock_logger.debug(
|
|
269
|
-
"Created context from dictionary",
|
|
270
|
-
state_vars=len(context.state),
|
|
271
|
-
history_records=len(context.history),
|
|
272
|
-
)
|
|
273
|
-
return context
|
|
274
|
-
except Exception as e:
|
|
275
|
-
flock_logger.error(
|
|
276
|
-
"Failed to create context from dictionary",
|
|
277
|
-
error=str(e),
|
|
278
|
-
)
|
|
279
|
-
raise
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
from flock.core.agent import Agent
|
|
4
|
-
from flock.core.context import FlockContext
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class HandoffBase:
|
|
8
|
-
"""Base class for handoff implementations."""
|
|
9
|
-
|
|
10
|
-
next_agent: str | Agent
|
|
11
|
-
input: dict[str, Any]
|
|
12
|
-
context: FlockContext
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
from types import TracebackType
|
|
3
|
-
|
|
4
|
-
from temporalio import workflow
|
|
5
|
-
|
|
6
|
-
with workflow.unsafe.imports_passed_through():
|
|
7
|
-
from rich.console import Console
|
|
8
|
-
from rich.panel import Panel
|
|
9
|
-
from rich.syntax import Syntax
|
|
10
|
-
from rich.traceback import Traceback
|
|
11
|
-
|
|
12
|
-
from flock.core.logging.logger import flock_logger
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class ErrorHandler:
|
|
16
|
-
"""Handles error formatting and display using Rich."""
|
|
17
|
-
|
|
18
|
-
def __init__(self, console: Console | None = None):
|
|
19
|
-
self.console = console or Console()
|
|
20
|
-
|
|
21
|
-
def format_exception(
|
|
22
|
-
self,
|
|
23
|
-
exc_type: type[BaseException],
|
|
24
|
-
exc_value: BaseException,
|
|
25
|
-
exc_tb: TracebackType,
|
|
26
|
-
*,
|
|
27
|
-
show_locals: bool = True,
|
|
28
|
-
) -> Panel:
|
|
29
|
-
"""Format an exception with Rich styling."""
|
|
30
|
-
# Create a Rich traceback
|
|
31
|
-
rich_tb = Traceback.from_exception(
|
|
32
|
-
exc_type,
|
|
33
|
-
exc_value,
|
|
34
|
-
exc_tb,
|
|
35
|
-
show_locals=show_locals,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
# If there's source code available, syntax highlight it
|
|
39
|
-
if exc_tb and exc_tb.tb_frame.f_code.co_filename != "<string>":
|
|
40
|
-
try:
|
|
41
|
-
with open(exc_tb.tb_frame.f_code.co_filename) as f:
|
|
42
|
-
source = f.read()
|
|
43
|
-
syntax = Syntax(
|
|
44
|
-
source,
|
|
45
|
-
"python",
|
|
46
|
-
line_numbers=True,
|
|
47
|
-
highlight_lines={exc_tb.tb_lineno},
|
|
48
|
-
)
|
|
49
|
-
except:
|
|
50
|
-
syntax = None
|
|
51
|
-
else:
|
|
52
|
-
syntax = None
|
|
53
|
-
|
|
54
|
-
# Create a panel with the traceback
|
|
55
|
-
return Panel(
|
|
56
|
-
rich_tb,
|
|
57
|
-
title=f"[red]{exc_type.__name__}[/]: {exc_value!s}",
|
|
58
|
-
border_style="red",
|
|
59
|
-
padding=(1, 2),
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
def handle_exception(
|
|
63
|
-
self,
|
|
64
|
-
exc_type: type[BaseException],
|
|
65
|
-
exc_value: BaseException,
|
|
66
|
-
exc_tb: TracebackType,
|
|
67
|
-
) -> None:
|
|
68
|
-
"""Handle an exception by formatting and displaying it."""
|
|
69
|
-
panel = self.format_exception(exc_type, exc_value, exc_tb)
|
|
70
|
-
self.console.print(panel)
|
|
71
|
-
# Also log the error through our logger
|
|
72
|
-
flock_logger.error(
|
|
73
|
-
f"Exception occurred: {exc_type.__name__}: {exc_value!s}",
|
|
74
|
-
error_type=exc_type.__name__,
|
|
75
|
-
error_details=str(exc_value),
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
def install(self) -> None:
|
|
79
|
-
"""Install this error handler as the default exception handler."""
|
|
80
|
-
sys.excepthook = self.handle_exception
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
# Global error handler instance
|
|
84
|
-
error_handler = ErrorHandler()
|
flock/core/logging/formatters.py
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
from devtools import pprint
|
|
4
|
-
from temporalio import workflow
|
|
5
|
-
|
|
6
|
-
with workflow.unsafe.imports_passed_through():
|
|
7
|
-
from rich.console import Console
|
|
8
|
-
from rich.panel import Panel
|
|
9
|
-
from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn, TimeElapsedColumn
|
|
10
|
-
from rich.table import Table
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class StructuredFormatter:
|
|
14
|
-
"""Formats structured data for Rich output."""
|
|
15
|
-
|
|
16
|
-
@staticmethod
|
|
17
|
-
def create_status_table(data: dict[str, Any]) -> Table:
|
|
18
|
-
"""Create a Rich table for displaying status information."""
|
|
19
|
-
table = Table(show_header=True, header_style="bold magenta")
|
|
20
|
-
table.add_column("Key")
|
|
21
|
-
table.add_column("Value")
|
|
22
|
-
|
|
23
|
-
for key, value in data.items():
|
|
24
|
-
table.add_row(str(key), str(value))
|
|
25
|
-
|
|
26
|
-
return table
|
|
27
|
-
|
|
28
|
-
@staticmethod
|
|
29
|
-
def create_progress_bar(description: str = "Progress") -> Progress:
|
|
30
|
-
"""Create a Rich progress bar with time tracking."""
|
|
31
|
-
return Progress(
|
|
32
|
-
SpinnerColumn(),
|
|
33
|
-
TextColumn("[progress.description]{task.description}"),
|
|
34
|
-
BarColumn(),
|
|
35
|
-
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
|
|
36
|
-
TimeElapsedColumn(),
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
@staticmethod
|
|
40
|
-
def create_workflow_panel(
|
|
41
|
-
workflow_id: str, status: str, details: dict[str, Any], title: str = "Workflow Status"
|
|
42
|
-
) -> Panel:
|
|
43
|
-
"""Create a Rich panel for workflow information."""
|
|
44
|
-
table = StructuredFormatter.create_status_table({"Workflow ID": workflow_id, "Status": status, **details})
|
|
45
|
-
return Panel(table, title=title, border_style="blue")
|
|
46
|
-
|
|
47
|
-
@staticmethod
|
|
48
|
-
def create_activity_panel(
|
|
49
|
-
activity_id: str, name: str, status: str, details: dict[str, Any], title: str = "Activity Status"
|
|
50
|
-
) -> Panel:
|
|
51
|
-
"""Create a Rich panel for activity information."""
|
|
52
|
-
table = StructuredFormatter.create_status_table(
|
|
53
|
-
{"Activity ID": activity_id, "Name": name, "Status": status, **details}
|
|
54
|
-
)
|
|
55
|
-
return Panel(table, title=title, border_style="magenta")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class PerformanceFormatter:
|
|
59
|
-
"""Formats performance metrics for Rich output."""
|
|
60
|
-
|
|
61
|
-
@staticmethod
|
|
62
|
-
def create_timing_tree(timings: dict[str, float]) -> str:
|
|
63
|
-
"""Create a tree-like structure showing execution timings."""
|
|
64
|
-
if not timings:
|
|
65
|
-
return "No timings recorded"
|
|
66
|
-
|
|
67
|
-
result = "Performance Metrics:\n"
|
|
68
|
-
for operation, duration in timings.items():
|
|
69
|
-
result += f"├── {operation}: {duration:.3f}s\n"
|
|
70
|
-
return result[:-1] # Remove trailing newline
|
|
71
|
-
|
|
72
|
-
@staticmethod
|
|
73
|
-
def create_performance_panel(metrics: dict[str, Any], title: str = "Performance Metrics") -> Panel:
|
|
74
|
-
"""Create a panel showing performance metrics."""
|
|
75
|
-
table = StructuredFormatter.create_status_table(metrics)
|
|
76
|
-
return Panel(table, title=title, border_style="cyan")
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
class AgentResultFormatter:
|
|
80
|
-
"""Formats agent results in a beautiful Rich table."""
|
|
81
|
-
|
|
82
|
-
@staticmethod
|
|
83
|
-
def format_result(result: dict[str, Any], agent_name: str) -> Panel:
|
|
84
|
-
"""Format an agent's result as a Rich panel containing a table."""
|
|
85
|
-
# Create a table with a nice header
|
|
86
|
-
table = Table(
|
|
87
|
-
show_header=True,
|
|
88
|
-
header_style="bold green",
|
|
89
|
-
title=f"Agent Results: {agent_name}",
|
|
90
|
-
title_style="bold blue",
|
|
91
|
-
border_style="bright_blue",
|
|
92
|
-
)
|
|
93
|
-
table.add_column("Output", style="cyan")
|
|
94
|
-
table.add_column("Value", style="green")
|
|
95
|
-
|
|
96
|
-
# Add each result to the table
|
|
97
|
-
for key, value in result.items():
|
|
98
|
-
# Format multi-line values (like blog headers) nicely
|
|
99
|
-
if isinstance(value, (list, tuple)) or (isinstance(value, str) and "\n" in value):
|
|
100
|
-
formatted_value = "\n".join(value) if isinstance(value, (list, tuple)) else value
|
|
101
|
-
# Add some padding for multi-line values
|
|
102
|
-
table.add_row(key, f"\n{formatted_value}\n")
|
|
103
|
-
else:
|
|
104
|
-
table.add_row(key, str(value))
|
|
105
|
-
|
|
106
|
-
pprint(result)
|
|
107
|
-
|
|
108
|
-
# Wrap the table in a panel for a nice border
|
|
109
|
-
return Panel(
|
|
110
|
-
table,
|
|
111
|
-
title="🎯 Agent Output",
|
|
112
|
-
title_align="left",
|
|
113
|
-
border_style="blue",
|
|
114
|
-
padding=(1, 2),
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
@staticmethod
|
|
118
|
-
def print_result(result: dict[str, Any], agent_name: str, console: Console | None = None) -> None:
|
|
119
|
-
"""Print an agent's result using Rich formatting."""
|
|
120
|
-
console = console or Console()
|
|
121
|
-
panel = AgentResultFormatter.format_result(result, agent_name)
|
|
122
|
-
console.print(panel)
|