Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename final driver field #1364

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING**: Removed `ImageQueryTask`, use `PromptTask` instead.
- **BREAKING**: Updated `ImageQueryTool.image_query_driver` to `ImageQueryTool.prompt_driver`.
- **BREAKING**: Updated `numpy` to `~2.0.2` and `pandas` to `^2.2`.
- **BREAKING**: Renamed `StructureRunTask.driver` to `StructureRunTask.structure_run_driver`.
- **BREAKING**: Renamed `StructureRunTool.driver` to `StructureRunTool.structure_run_driver`.
- File Manager Driver path logic has been improved.
- `LocalFileManagerDriver.workdir` can now be a relative path or absolute path. Relative paths will be prefixed with the current working directory.
- `AmazonS3FileManagerDriver.workdir` can now be a relative path or absolute path. Relative paths will be prefixed with `/`.
Expand Down
26 changes: 26 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,32 @@ pipeline = Pipeline(
pipeline.run("Describe the weather in the image")
```

### Renamed `StructureRunTask.driver`/`StructureRunTool.driver` to `StructureRunTask.structure_run_driver`/`StructureRunTool.structure_run_driver`

`StructureRunTask.driver` and `StructureRunTool.driver` have been renamed to `StructureRunTask.structure_run_driver` and `StructureRunTool.structure_run_driver` respectively.

#### Before

```python
StructureRunTask(
driver=LocalStructureRunDriver(),
)
StructureRunTool(
driver=LocalStructureRunDriver(),
)
```

#### After

```python
StructureRunTask(
structure_run_driver=LocalStructureRunDriver(),
)
StructureRunTool(
structure_run_driver=LocalStructureRunDriver(),
)
```

## 0.33.X to 0.34.X

### `AnthropicDriversConfig` Embedding Driver
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/src/multi_agent_workflow_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def build_writer(role: str, goal: str, backstory: str) -> Agent:
Pinpoint major trends, breakthroughs, and their implications for various industries.""",
),
id="research",
driver=LocalStructureRunDriver(
structure_run_driver=LocalStructureRunDriver(
create_structure=build_researcher,
),
),
Expand All @@ -149,7 +149,7 @@ def build_writer(role: str, goal: str, backstory: str) -> Agent:
Insights:
{{ parent_outputs["research"] }}""",
),
driver=LocalStructureRunDriver(
structure_run_driver=LocalStructureRunDriver(
create_structure=lambda writer=writer: build_writer(
role=writer["role"],
goal=writer["goal"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def build_joke_rewriter() -> Agent:
joke_coordinator = Pipeline(
tasks=[
StructureRunTask(
driver=LocalStructureRunDriver(
structure_run_driver=LocalStructureRunDriver(
create_structure=build_joke_teller,
),
),
StructureRunTask(
("Rewrite this joke: {{ parent_output }}",),
driver=LocalStructureRunDriver(
structure_run_driver=LocalStructureRunDriver(
create_structure=build_joke_rewriter,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
tasks=[
StructureRunTask(
("Think of a question related to Retrieval Augmented Generation.",),
driver=LocalStructureRunDriver(
structure_run_driver=LocalStructureRunDriver(
create_structure=lambda: Agent(
rules=[
Rule(
Expand All @@ -29,7 +29,7 @@
),
StructureRunTask(
("{{ parent_output }}",),
driver=GriptapeCloudStructureRunDriver(
structure_run_driver=GriptapeCloudStructureRunDriver(
base_url=base_url,
api_key=api_key,
structure_id=structure_id,
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/structures/src/tasks_16.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def build_writer() -> Agent:
"""Perform a detailed examination of the newest developments in AI as of 2024.
Pinpoint major trends, breakthroughs, and their implications for various industries.""",
),
driver=LocalStructureRunDriver(create_structure=build_researcher),
structure_run_driver=LocalStructureRunDriver(create_structure=build_researcher),
),
StructureRunTask(
(
Expand All @@ -122,7 +122,7 @@ def build_writer() -> Agent:
Keep the tone appealing and use simple language to make it less technical.""",
"{{parent_output}}",
),
driver=LocalStructureRunDriver(create_structure=build_writer),
structure_run_driver=LocalStructureRunDriver(create_structure=build_writer),
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

structure_run_tool = StructureRunTool(
description="RAG Expert Agent - Structure to invoke with natural language queries about the topic of Retrieval Augmented Generation",
driver=GriptapeCloudStructureRunDriver(
structure_run_driver=GriptapeCloudStructureRunDriver(
base_url=base_url,
api_key=api_key,
structure_id=structure_id,
Expand Down
8 changes: 4 additions & 4 deletions griptape/tasks/structure_run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class StructureRunTask(PromptTask):
"""Task to run a Structure.

Attributes:
driver: Driver to run the Structure.
structure_run_driver: Driver to run the Structure.
"""

driver: BaseStructureRunDriver = field(kw_only=True)
structure_run_driver: BaseStructureRunDriver = field(kw_only=True)

def try_run(self) -> BaseArtifact:
if isinstance(self.input, ListArtifact):
return self.driver.run(*self.input.value)
return self.structure_run_driver.run(*self.input.value)
else:
return self.driver.run(self.input)
return self.structure_run_driver.run(self.input)
6 changes: 3 additions & 3 deletions griptape/tools/structure_run/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class StructureRunTool(BaseTool):

Attributes:
description: A description of what the Structure does.
driver: Driver to run the Structure.
structure_run_driver: Driver to run the Structure.
"""

description: str = field(kw_only=True)
driver: BaseStructureRunDriver = field(kw_only=True)
structure_run_driver: BaseStructureRunDriver = field(kw_only=True)

@activity(
config={
Expand All @@ -40,4 +40,4 @@ class StructureRunTool(BaseTool):
def run_structure(self, params: dict) -> BaseArtifact:
args: list[str] = params["values"]["args"]

return self.driver.run(*[TextArtifact(arg) for arg in args])
return self.structure_run_driver.run(*[TextArtifact(arg) for arg in args])
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_run(self):
pipeline = Pipeline()
driver = LocalStructureRunDriver(create_structure=lambda: Agent())

task = StructureRunTask(driver=driver)
task = StructureRunTask(structure_run_driver=driver)

pipeline.add_task(task)

Expand All @@ -23,7 +23,7 @@ def test_run_with_env(self, mock_config):
mock_config.drivers_config.prompt_driver = MockPromptDriver(mock_output=lambda _: os.environ["KEY"])
agent = Agent()
driver = LocalStructureRunDriver(create_structure=lambda: agent, env={"KEY": "value"})
task = StructureRunTask(driver=driver)
task = StructureRunTask(structure_run_driver=driver)

pipeline.add_task(task)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/tasks/test_structure_run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_run_single_input(self, mock_config):
pipeline = Pipeline()
driver = LocalStructureRunDriver(create_structure=lambda: agent)

task = StructureRunTask(driver=driver)
task = StructureRunTask(structure_run_driver=driver)

pipeline.add_task(task)

Expand All @@ -25,7 +25,7 @@ def test_run_multiple_inputs(self, mock_config):
pipeline = Pipeline()
driver = LocalStructureRunDriver(create_structure=lambda: agent)

task = StructureRunTask(input=["foo", "bar", "baz"], driver=driver)
task = StructureRunTask(input=["foo", "bar", "baz"], structure_run_driver=driver)

pipeline.add_task(task)

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/tools/test_structure_run_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class TestStructureRunTool:
def client(self):
agent = Agent()

return StructureRunTool(description="foo bar", driver=LocalStructureRunDriver(create_structure=lambda: agent))
return StructureRunTool(
description="foo bar", structure_run_driver=LocalStructureRunDriver(create_structure=lambda: agent)
)

def test_run_structure(self, client):
assert client.run_structure({"values": {"args": "foo bar"}}).value == "mock output"
Expand Down