fabricatio-agent 0.2.4.dev7__cp314-cp314-win_amd64.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.
@@ -0,0 +1 @@
1
+ """An extension of fabricatio."""
@@ -0,0 +1 @@
1
+ """Actions defined in fabricatio-agent."""
@@ -0,0 +1,96 @@
1
+ """Built-in actions."""
2
+
3
+ from typing import ClassVar, List, Optional, Set
4
+
5
+ from fabricatio_core import Action, Task, logger
6
+ from fabricatio_core.models.containers import CodeSnippet
7
+ from fabricatio_core.utils import ok
8
+ from fabricatio_tool.capabilities.handle_task import HandleTask
9
+ from fabricatio_tool.models.tool import ToolBox
10
+ from fabricatio_tool.rust import treeview
11
+ from fabricatio_tool.toolboxes import fs_toolbox
12
+ from pydantic import Field
13
+
14
+ from fabricatio_agent.capabilities.agent import Agent
15
+
16
+
17
+ class WriteCode(Action, Agent):
18
+ """Write code. output the code as a string."""
19
+
20
+ ctx_override: ClassVar[bool] = True
21
+
22
+ toolboxes: Set[ToolBox] = Field(default={fs_toolbox})
23
+
24
+ output_key: str = "code"
25
+
26
+ coding_language: Optional[str] = None
27
+ """The coding language to use, will automatically be inferred from the prompt if not specified."""
28
+
29
+ async def _execute(self, task_input: Task, **cxt) -> Optional[List[CodeSnippet]]:
30
+ c_seq = ok(
31
+ await self.acode_snippets(
32
+ f"current directory tree:\n{treeview()}\n\n{task_input.assembled_prompt}",
33
+ code_language=self.coding_language,
34
+ )
35
+ )
36
+
37
+ for c in c_seq:
38
+ c.write()
39
+
40
+ return c_seq
41
+
42
+
43
+ class CleanUp(Action, Agent, HandleTask):
44
+ """Clean up the workspace."""
45
+
46
+ toolboxes: Set[ToolBox] = Field(default={fs_toolbox})
47
+
48
+ async def _execute(self, task_input: Task, **cxt) -> None:
49
+ """Execute the action."""
50
+ await self.handle_task(task_input, {})
51
+
52
+
53
+ class MakeSpecification(Action, Agent):
54
+ """Make a specification for a task."""
55
+
56
+ ctx_override: ClassVar[bool] = True
57
+
58
+ output_key: str = "specification"
59
+
60
+ async def _execute(self, prompt: str, **cxt) -> Optional[str]:
61
+ """Execute the action."""
62
+
63
+
64
+ class Planning(Action, Agent):
65
+ """Architectural design and planning action."""
66
+
67
+ ctx_override: ClassVar[bool] = True
68
+
69
+ sequential_thinking: bool = False
70
+ """Whether to use sequential thinking."""
71
+
72
+ async def _execute(self, task_input: Task, **cxt) -> bool:
73
+ """Execute the action."""
74
+ req = f"Current directory tree:\n{treeview()}\n\n{task_input.assembled_prompt}"
75
+ if self.sequential_thinking:
76
+ planning = await self.thinking(req)
77
+ req += f"\n\n{planning.export_branch_string()}"
78
+
79
+ tk = ok(await self.cooperative_digest(req, False))
80
+ logger.debug(f"Execute tasklist:\n{tk.explain()}")
81
+ await (
82
+ tk.inject_context(sequential_thinking=self.sequential_thinking)
83
+ .inject_description(f"This task is a sub task of {task_input.name}.")
84
+ .execute()
85
+ )
86
+ return True
87
+
88
+
89
+ class ReviewCode(Action, Agent):
90
+ """Review code and suggest improvements."""
91
+
92
+ ctx_override: ClassVar[bool] = True
93
+
94
+ async def _execute(self, prompt: str, **cxt) -> Optional[str]:
95
+ """Execute the action."""
96
+ return self.save_checkpoint()
@@ -0,0 +1 @@
1
+ """Capabilities defined in fabricatio-agent."""
@@ -0,0 +1,100 @@
1
+ """Agent capability implementation."""
2
+
3
+ from abc import ABC
4
+ from typing import Any, List, Optional, Unpack
5
+
6
+ from fabricatio_capabilities.capabilities.task import DispatchTask
7
+ from fabricatio_capable.capabilities.capable import Capable
8
+ from fabricatio_checkpoint.capabilities.checkpoint import Checkpoint
9
+ from fabricatio_core.models.kwargs_types import GenerateKwargs
10
+ from fabricatio_core.rust import TEMPLATE_MANAGER
11
+ from fabricatio_core.utils import ok
12
+ from fabricatio_diff.capabilities.diff_edit import DiffEdit
13
+ from fabricatio_judge.capabilities.advanced_judge import EvidentlyJudge
14
+ from fabricatio_memory.capabilities.remember import Remember
15
+ from fabricatio_question.capabilities.questioning import Questioning
16
+ from fabricatio_rule.capabilities.censor import Censor
17
+ from fabricatio_team.capabilities.digest import CooperativeDigest
18
+ from fabricatio_thinking.capabilities.thinking import Thinking
19
+ from fabricatio_tool.capabilities.handle import Handle
20
+
21
+ from fabricatio_agent.config import agent_config
22
+
23
+
24
+ class Agent(
25
+ Checkpoint,
26
+ Capable,
27
+ CooperativeDigest,
28
+ Remember,
29
+ Censor,
30
+ EvidentlyJudge,
31
+ DispatchTask,
32
+ DiffEdit,
33
+ Questioning,
34
+ Thinking,
35
+ Handle,
36
+ ABC,
37
+ ):
38
+ """Main agent class that integrates multiple capabilities to fulfill requests.
39
+
40
+ This class combines various capabilities like memory, thinking, task dispatching,
41
+ and team cooperation to process and fulfill user requests.
42
+ """
43
+
44
+ async def fulfill(
45
+ self,
46
+ request: str,
47
+ sequential_thinking: Optional[bool] = None,
48
+ check_capable: bool = False,
49
+ memory: bool = False,
50
+ top_k: int = 100,
51
+ boost_recent: bool = True,
52
+ **kwargs: Unpack[GenerateKwargs],
53
+ ) -> None | List[Any]:
54
+ """Process and fulfill a request using various agent capabilities.
55
+
56
+ Args:
57
+ request (str): The request to be fulfilled.
58
+ sequential_thinking (Optional[bool], optional): Whether to use sequential thinking.
59
+ Defaults to None.
60
+ check_capable (bool, optional): Whether to check agent capabilities before processing.
61
+ Defaults to False.
62
+ memory (bool, optional): Whether to use memory in processing. Defaults to False.
63
+ top_k (int, optional): Number of top memories to recall. Defaults to 100.
64
+ boost_recent (bool, optional): Whether to boost recent memories. Defaults to True.
65
+ **kwargs (Unpack[GenerateKwargs]): Additional keyword arguments for generation.
66
+
67
+ Returns:
68
+ None | List[Any]: None if not capable, otherwise a list of execution results.
69
+
70
+ Note:
71
+ The method integrates multiple capabilities:
72
+
73
+ - Checks capabilities if required
74
+ - Recalls memories if enabled
75
+ - Performs sequential thinking if enabled
76
+ - Digests the request into tasks
77
+ - Executes the generated task list
78
+ """
79
+ if (check_capable or agent_config.check_capable) and not await self.capable(request, **kwargs): # pyright: ignore [reportCallIssue]
80
+ return None
81
+ mem = ""
82
+ thought = ""
83
+ if memory or agent_config.memory:
84
+ mem = await self.recall(request, top_k, boost_recent, **kwargs)
85
+
86
+ if sequential_thinking or agent_config.sequential_thinking:
87
+ thought = (await self.thinking(request, **kwargs)).export_branch_string()
88
+
89
+ task_list = ok(
90
+ await self.digest(
91
+ TEMPLATE_MANAGER.render_template(
92
+ agent_config.fulfill_prompt_template, {"request": request, "mem": mem, "thoughts": thought}
93
+ ),
94
+ ok(self.team_roster),
95
+ **kwargs,
96
+ )
97
+ )
98
+ task_list.add_before_exec_hook(lambda: self.save_checkpoint(f"{request[:50]}..."))
99
+
100
+ return await task_list.execute()
@@ -0,0 +1,148 @@
1
+ """CLI entry point."""
2
+
3
+ from fabricatio_core.utils import cfg
4
+
5
+ cfg(feats=["cli"])
6
+ from enum import StrEnum
7
+ from typing import Dict
8
+
9
+ from fabricatio_core import Event, Role, Task, WorkFlow
10
+ from fabricatio_core.rust import is_installed
11
+ from fabricatio_team.capabilities.team import Cooperate
12
+ from fabricatio_team.models.team import Team
13
+ from pydantic import Field
14
+ from typer import Argument, Option, Typer
15
+
16
+ from fabricatio_agent.actions.code import CleanUp, Planning, WriteCode
17
+
18
+
19
+ class TaskType(StrEnum):
20
+ """Task types."""
21
+
22
+ Coding = "coding"
23
+ Orchestrate = "orchestrate"
24
+ CleanUp = "cleanup"
25
+ Plot = "plot"
26
+ Synthesize = "synthesize"
27
+ Test = "test"
28
+ Documentation = "documentation"
29
+
30
+
31
+ app = Typer()
32
+
33
+ dev_reg = {
34
+ Event.quick_instantiate(TaskType.Coding): WorkFlow(
35
+ name="WriteCodeWorkFlow",
36
+ description="Generate desired code and then write that code to a file",
37
+ steps=(WriteCode().to_task_output(),),
38
+ ),
39
+ Event.quick_instantiate(TaskType.CleanUp): WorkFlow(
40
+ name="CleanWorkFlow",
41
+ description="Clean unwanted files or directories.",
42
+ steps=(CleanUp().to_task_output(),),
43
+ ),
44
+ }
45
+
46
+ if is_installed("fabricatio_plot"):
47
+ from fabricatio_plot.actions.fs import SaveDataCSV
48
+ from fabricatio_plot.actions.plot import MakeCharts
49
+ from fabricatio_plot.actions.synthesize import MakeSynthesizedData
50
+
51
+ dev_reg.update(
52
+ {
53
+ Event.quick_instantiate(TaskType.Plot): WorkFlow(
54
+ name="PlotWorkFlow",
55
+ description="Generate plots and charts using matplotlib and save to fs.",
56
+ steps=(MakeCharts().to_task_output(),),
57
+ ),
58
+ Event.quick_instantiate(TaskType.Synthesize): WorkFlow(
59
+ name="SynthesizeWorkFlow",
60
+ description="Synthesize data using synthesize data capabilities.",
61
+ steps=(
62
+ MakeSynthesizedData(output_key="data_to_save"),
63
+ SaveDataCSV().to_task_output(),
64
+ ),
65
+ ),
66
+ }
67
+ )
68
+
69
+
70
+ class Developer(Role, Cooperate):
71
+ """A developer role capable of handling coding tasks."""
72
+
73
+ skills: Dict[Event, WorkFlow] = Field(
74
+ default_factory=lambda: dev_reg,
75
+ frozen=True,
76
+ )
77
+ """The registry of events and workflows."""
78
+
79
+
80
+ class TestEngineer(Role, Cooperate):
81
+ """A test engineer role for generating test cases."""
82
+
83
+ skills: Dict[Event, WorkFlow] = Field(
84
+ default_factory=lambda: {
85
+ Event.quick_instantiate(TaskType.Test): WorkFlow(
86
+ name="GenerateTestcasesWorkFlow",
87
+ description="Generate test cases for the given task.",
88
+ steps=(WriteCode().to_task_output(),),
89
+ )
90
+ }
91
+ )
92
+
93
+
94
+ class DocumentationWriter(Role, Cooperate):
95
+ """A documentation writer role for writing documentation."""
96
+
97
+ skills: Dict[Event, WorkFlow] = Field(
98
+ default_factory=lambda: {
99
+ Event.quick_instantiate(TaskType.Test): WorkFlow(
100
+ name="GenerateDocumentationWorkFlow",
101
+ description="Generate documentation for the given task.",
102
+ steps=(WriteCode().to_task_output(),),
103
+ )
104
+ }
105
+ )
106
+
107
+
108
+ class ProjectLeader(Role, Cooperate):
109
+ """A project leader role capable of handling planning tasks.
110
+
111
+ This role implements the Cooperate capability and maintains a registry of workflows
112
+ for different task types. The project leader can execute planning tasks through the
113
+ PlanningWorkFlow which breaks down complex tasks into smaller subtasks.
114
+ """
115
+
116
+ skills: Dict[Event, WorkFlow] = Field(
117
+ default_factory=lambda: {
118
+ Event.quick_instantiate(TaskType.Orchestrate): WorkFlow(
119
+ name="OrchestrateWorkFlow",
120
+ description="This workflow is extremely expensive, so YOU SHALL use this as less as possible, you can use this only when necessary. Capable to finish task that is completely beyond your reach, but do add enough detailed context into task metadata. ",
121
+ steps=(Planning().to_task_output(),),
122
+ ),
123
+ },
124
+ frozen=True,
125
+ )
126
+ """The registry of events and workflows."""
127
+
128
+
129
+ @app.command(no_args_is_help=True)
130
+ def code(
131
+ prompt: str = Argument(..., help="The prompt to generate code from."),
132
+ sequential_thinking: bool = Option(
133
+ False, "-sq", "--sequential-thinking", help="Whether to use sequential thinking."
134
+ ),
135
+ ) -> None:
136
+ """Generate code based on the provided prompt.
137
+
138
+ This function creates a development team with a Developer role and dispatches
139
+ a coding task. If the task is complex, it will be broken down into smaller
140
+ subtasks through the architect workflow.
141
+ """
142
+ Team().join(Developer()).join(ProjectLeader()).join(TestEngineer()).join(DocumentationWriter()).inform().dispatch()
143
+ task = Task(name="Write code", description=prompt).update_init_context(sequential_thinking=sequential_thinking)
144
+ task.delegate_blocking(TaskType.Orchestrate)
145
+
146
+
147
+ if __name__ == "__main__":
148
+ app()
@@ -0,0 +1,24 @@
1
+ """Module containing configuration classes for fabricatio-agent."""
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from fabricatio_core import CONFIG
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class AgentConfig:
10
+ """Configuration for fabricatio-agent."""
11
+
12
+ memory: bool = False
13
+ """Whether to use memory."""
14
+ sequential_thinking: bool = False
15
+ """Whether to think sequentially."""
16
+ check_capable: bool = False
17
+ """Whether to check if the agent is capable of performing the task."""
18
+ fulfill_prompt_template: str = "built-in/fulfill_prompt"
19
+ """The prompt template to use for fulfill."""
20
+
21
+
22
+ agent_config = CONFIG.load("agent", AgentConfig)
23
+
24
+ __all__ = ["agent_config"]
@@ -0,0 +1 @@
1
+ """Models defined in fabricatio-agent."""
@@ -0,0 +1 @@
1
+ """This module contains the models for the agent."""
File without changes
@@ -0,0 +1 @@
1
+ """Rust bindings for the Rust API of fabricatio-agent."""
@@ -0,0 +1 @@
1
+ """Workflows defined in fabricatio-agent."""
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: fabricatio-agent
3
+ Version: 0.2.4.dev7
4
+ Classifier: License :: OSI Approved :: MIT License
5
+ Classifier: Programming Language :: Python :: 3.12
6
+ Classifier: Programming Language :: Python :: 3.13
7
+ Classifier: Programming Language :: Python :: 3.14
8
+ Classifier: Programming Language :: Python :: Implementation :: CPython
9
+ Classifier: Typing :: Typed
10
+ Requires-Dist: fabricatio-core
11
+ Requires-Dist: fabricatio-digest
12
+ Requires-Dist: fabricatio-memory
13
+ Requires-Dist: fabricatio-improve
14
+ Requires-Dist: fabricatio-rule
15
+ Requires-Dist: fabricatio-judge
16
+ Requires-Dist: fabricatio-capabilities
17
+ Requires-Dist: fabricatio-diff
18
+ Requires-Dist: fabricatio-thinking
19
+ Requires-Dist: fabricatio-question
20
+ Requires-Dist: fabricatio-tool
21
+ Requires-Dist: fabricatio-team
22
+ Requires-Dist: fabricatio-capable
23
+ Requires-Dist: fabricatio-checkpoint
24
+ Requires-Dist: typer-slim[standard]>=0.15.2 ; extra == 'cli'
25
+ Requires-Dist: fabricatio-actions ; extra == 'cli'
26
+ Requires-Dist: fabricatio-agent[cli] ; extra == 'cli-plot'
27
+ Requires-Dist: fabricatio-plot ; extra == 'cli-plot'
28
+ Requires-Dist: fabricatio-agent[cli] ; extra == 'cli-full'
29
+ Requires-Dist: fabricatio-agent[cli-plot] ; extra == 'cli-full'
30
+ Provides-Extra: cli
31
+ Provides-Extra: cli-plot
32
+ Provides-Extra: cli-full
33
+ Summary: An extension of fabricatio
34
+ Author-email: Whth <zettainspector@foxmail.com>
35
+ License-Expression: MIT
36
+ Requires-Python: >=3.12, <3.15
37
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
38
+ Project-URL: Homepage, https://github.com/Whth/fabricatio
39
+ Project-URL: Repository, https://github.com/Whth/fabricatio
40
+ Project-URL: Issues, https://github.com/Whth/fabricatio/issues
41
+
42
+ # `fabricatio-agent`
43
+
44
+ [MIT](https://img.shields.io/badge/license-MIT-blue.svg)
45
+ ![Python Versions](https://img.shields.io/pypi/pyversions/fabricatio-agent)
46
+ [![PyPI Version](https://img.shields.io/pypi/v/fabricatio-agent)](https://pypi.org/project/fabricatio-agent/)
47
+ [![PyPI Downloads](https://static.pepy.tech/badge/fabricatio-agent/week)](https://pepy.tech/projects/fabricatio-agent)
48
+ [![PyPI Downloads](https://static.pepy.tech/badge/fabricatio-agent)](https://pepy.tech/projects/fabricatio-agent)
49
+ [![Bindings: PyO3](https://img.shields.io/badge/bindings-pyo3-green)](https://github.com/PyO3/pyo3)
50
+ [![Build Tool: uv + maturin](https://img.shields.io/badge/built%20with-uv%20%2B%20maturin-orange)](https://github.com/astral-sh/uv)
51
+
52
+ An extension of fabricatio.
53
+
54
+ ---
55
+
56
+ ## 📦 Installation
57
+
58
+ This package is part of the `fabricatio` monorepo and can be installed as an optional dependency using either pip or uv:
59
+
60
+ ```bash
61
+ pip install fabricatio[agent]
62
+ # or
63
+ uv pip install fabricatio[agent]
64
+ ```
65
+
66
+ For a full installation that includes this package and all other components of `fabricatio`:
67
+
68
+ ```bash
69
+ pip install fabricatio[full]
70
+ # or
71
+ uv pip install fabricatio[full]
72
+ ```
73
+
74
+ ## 🔍 Overview
75
+
76
+ Provides a comprehensive AI agent framework that integrates multiple capabilities for autonomous task fulfillment. The
77
+ agent combines thinking, memory, team cooperation, and various specialized capabilities to process and execute complex
78
+ requests, making it a central orchestrator in the fabricatio ecosystem for intelligent workflow automation.
79
+
80
+ ## 🧩 Key Features
81
+
82
+ - **Multi-Capability Integration**: Combines thinking, memory, judgment, task dispatching, and team cooperation
83
+ capabilities
84
+ - **Autonomous Task Fulfillment**: Processes requests through sequential thinking and task decomposition
85
+ - **Memory-Augmented Processing**: Recalls relevant information to enhance decision making and context awareness
86
+ - **Team Collaboration**: Supports cooperative workflows with multiple specialized agents
87
+ - **Configurable Behavior**: Customizable settings for thinking mode, memory usage, and capability checking
88
+ - **Template-Driven Execution**: Uses configurable prompt templates for consistent and adaptable behavior
89
+
90
+ ## 🔗 Dependencies
91
+
92
+ Core dependencies:
93
+
94
+ - `fabricatio-core` - Core interfaces and utilities
95
+ - `fabricatio-digest` - Request digestion and task planning
96
+ - `fabricatio-memory` - Memory management and recall
97
+ - `fabricatio-improve` - Content improvement capabilities
98
+ - `fabricatio-rule` - Rule-based content processing
99
+ - `fabricatio-judge` - Advanced judgment and evaluation
100
+ - `fabricatio-capabilities` - Base capability patterns
101
+ - `fabricatio-diff` - Difference editing operations
102
+ - `fabricatio-thinking` - Sequential thinking processes
103
+ - `fabricatio-question` - Interactive questioning
104
+ - `fabricatio-tool` - Tool handling and execution
105
+ - `fabricatio-team` - Team cooperation mechanisms
106
+ - `fabricatio-capable` - Capability assessment
107
+
108
+ ## 📄 License
109
+
110
+ MIT – see [LICENSE](../../LICENSE)
111
+
112
+
@@ -0,0 +1,17 @@
1
+ fabricatio_agent-0.2.4.dev7.dist-info/METADATA,sha256=69xHb_ffiJ3RkyeXS3t_YjorrGMSbv2rX59z1XhBq50,4702
2
+ fabricatio_agent-0.2.4.dev7.dist-info/WHEEL,sha256=ZrAiv7lKoKZh206bhSq4g-n3q3ySUOJQmQ4WXAA7TE8,97
3
+ fabricatio_agent-0.2.4.dev7.dist-info/entry_points.txt,sha256=3KDr1lHnm25WWKwwD_3J9QE1DGzaSpUtpcKQfx6deAQ,50
4
+ fabricatio_agent/__init__.py,sha256=gumbL2CwfKm4bnxOVpyhYxAIwfVldHTB30OCZBtxxMw,35
5
+ fabricatio_agent/actions/__init__.py,sha256=GECfG19Lfbvqx67Fx2i25naQKq1ikTp7Lvu3ZGYdohY,44
6
+ fabricatio_agent/actions/code.py,sha256=hATW88iwvfC9gprJGrZWLgN25neNHkofZsvG7N2X_Ms,3044
7
+ fabricatio_agent/capabilities/__init__.py,sha256=qpalNLgxQnKNcYTw1HdeCPcgV4edsqtQcM7YWYoa9ak,49
8
+ fabricatio_agent/capabilities/agent.py,sha256=iuLeBhuQZ4TFJpJYVCwi95jJhIQ_j-dsUzNeUS9aC7E,3992
9
+ fabricatio_agent/cli.py,sha256=9FkKnLh-QOIQPWCgZ74t1vX5MmxO9qLS7vyrB3GrVq8,5209
10
+ fabricatio_agent/config.py,sha256=w1tVP2sci0yGAK_tgF9KGowiOA0QUFPzT-TG21jQ49Y,689
11
+ fabricatio_agent/models/__init__.py,sha256=c0QznffHLV2_7YYd32u0X6MNaqvW1lr8chDZRznFU8o,43
12
+ fabricatio_agent/models/agent.py,sha256=hX3DdWT99VK2AdqKK0_NZGfRnci8M7c05OY9eaBcIkc,54
13
+ fabricatio_agent/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ fabricatio_agent/rust.cp314-win_amd64.pyd,sha256=lwbWGaqar8VqdqwA67b1EQwuzzDhiKm_a40tECdwi8g,284672
15
+ fabricatio_agent/rust.pyi,sha256=96hRXiP7K2n2ztjK6mLENMF4GMgMWySvR7sjvWiO7bg,59
16
+ fabricatio_agent/workflows/__init__.py,sha256=eWbhVVtOrwYxioz0UZ5u6sBqVZtXKmTCeQCQDfKH5Ns,46
17
+ fabricatio_agent-0.2.4.dev7.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.10.2)
3
+ Root-Is-Purelib: false
4
+ Tag: cp314-cp314-win_amd64
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ falcon=fabricatio_agent.cli:app