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

Add structure run tool/task #767

Merged
merged 26 commits into from
May 6, 2024
Merged

Add structure run tool/task #767

merged 26 commits into from
May 6, 2024

Conversation

collindutter
Copy link
Member

@collindutter collindutter commented May 1, 2024

Added

  • StructureRunClient for running other Griptapes via a Tool.
  • StructureRunTask for running Structures as a Task from within another Structure.
  • GriptapeCloudStructureRunDriver for running Structures in the Griptape Cloud.
  • LocalStructureRunDriver for running Structures in the same runtime environment as the code that is running the Structure.
  • Default run_fn to CodeExecutionTask, making it a suitable no-op Task.

📚 Documentation preview 📚: https://griptape--767.org.readthedocs.build//767/

@collindutter collindutter force-pushed the feature/structure-run-tool branch 3 times, most recently from 46c4d0c to 70eb6db Compare May 2, 2024 00:17
CHANGELOG.md Outdated
@@ -24,7 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `AmazonS3FileManagerDriver` for managing files on Amazon S3.
- `MediaArtifact` as a base class for `ImageArtifact` and future media Artifacts.
- Optional `exception` field to `ErrorArtifact`.
- `GriptapeCloudStructureRunClient` tool for invoking Griptape Cloud Structure Run APIs.
- `GriptapeCloudStructureRunClient` Tool for invoking Griptape Cloud Structure Run APIs.
- `GriptapeStructureRunClient` Tool for through a Tool.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tool for RUNNING a Structure from within a Structure?

In this example we implement a multi-agent Workflow we have a single "Researcher" Agent that conducts research on a topic, and then fans out to multiple "Writer" Agents to write blog posts based on the research.

By splitting up our workloads across multiple Structures, we can parallelize the work and leverage the strengths of each Agent. The Researcher can focus on gathering data and insights, while the Writers can focus on crafting engaging narratives.
Additionally, this opens us up to the possibility of having each Agent run on a separate machine or container, allowing us to scale our Workflow as needed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be coy here; let's talk about "we can solve these in parallel using Griptape Cloud managed Structures to solve these simultaneously and get it faster" or whatever.

docs/examples/multi-agent-workflow.md Show resolved Hide resolved
with open(f"{Path(__file__).parent}/writers.json", "r") as f:
writers = json.loads(f.read())

# Build the crew
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...team...?

docs/examples/multi-agent-workflow.md Outdated Show resolved Hide resolved
@collindutter collindutter force-pushed the feature/structure-run-tool branch 2 times, most recently from ac94922 to 0ac5bc9 Compare May 2, 2024 16:13
"""Task to run a Structure.

Attributes:
structure_to_run: Structure to run.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awkward field name but structure is already taken by BaseTask. Open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_structure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

"""

description: str = field(kw_only=True)
structure: Structure = field(kw_only=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this consistent with the awkward structure_to_run on the Task?

@collindutter collindutter requested a review from a team May 2, 2024 16:29
@collindutter collindutter marked this pull request as ready for review May 2, 2024 16:29
SavagePencil
SavagePencil previously approved these changes May 2, 2024
docs/examples/multi-agent-workflow.md Show resolved Hide resolved
Copy link
Contributor

@dylanholmes dylanholmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

I really like seeing the doc examples in the same PR (and its also nice that they just happen to show up at the beginning of the list the files).

CHANGELOG.md Outdated Show resolved Hide resolved
docs/examples/multi-agent-workflow.md Outdated Show resolved Hide resolved
docs/examples/multi-agent-workflow.md Outdated Show resolved Hide resolved
docs/examples/multi-agent-workflow.md Show resolved Hide resolved
docs/examples/multi-agent-workflow.md Show resolved Hide resolved
docs/griptape-framework/structures/tasks.md Outdated Show resolved Hide resolved
griptape/tasks/code_execution_task.py Outdated Show resolved Hide resolved
@collindutter collindutter force-pushed the feature/structure-run-tool branch 3 times, most recently from df075cb to fd616f3 Compare May 3, 2024 22:47
SavagePencil
SavagePencil previously approved these changes May 4, 2024
Copy link
Member

@SavagePencil SavagePencil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qs only.

CHANGELOG.md Outdated
- `GriptapeCloudStructureRunClient` tool for invoking Griptape Cloud Structure Run APIs.
- `StructureRunClient` for running other Structures via a Tool.
- `StructureRunTask` for running Structures as a Task from within another Structure.
- `GriptapeCloudStructureRunDriver` for running Structures in the Griptape Cloud.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this ONLY work for Cloud or will it work for the emulator as well?

@@ -23,7 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `AmazonS3FileManagerDriver` for managing files on Amazon S3.
- `MediaArtifact` as a base class for `ImageArtifact` and future media Artifacts.
- Optional `exception` field to `ErrorArtifact`.
- `GriptapeCloudStructureRunClient` tool for invoking Griptape Cloud Structure Run APIs.
- `StructureRunClient` for running other Structures via a Tool.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh why can't it end with Tool

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named it this way for consistency TaskMemoryClient, another Tool that interacts directly with the framework. Agree that it's not ideal but it's at least consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boo but OK. In the future, we don't let consistency hold us back :)

Identify key trends, breakthrough technologies, and potential industry impacts.""",
),
driver=LocalStructureRunDriver(
structure_factory_fn=lambda: researcher,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Learning from the pitfall Jason fell into when reusing the same instance for multiple runs, maybe all the examples should use actually factory functions that return new instances. That way if someone starts out with one of our examples, they'll be on the right path from the beginning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, updated.

"""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.""",
id="research",
target_structure=build_researcher(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to LocalStructureRunDriver, StructureRunTask should accept a structure_factory_fn instead of an actual Structure instance to avoid the pitfalls of shared state between concurrent runs, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually a mistake in the examples, target_structure is no longer a field. The Tool takes a Driver just like the Task.

Comment on lines -37 to +40
- **BREADKING**: Removed `mime_type` field from `ImageArtifact`. `mime_type` is now a property constructed using the Artifact type and `format` field.
- **BREAKING**: Removed `mime_type` field from `ImageArtifact`. `mime_type` is now a property constructed using the Artifact type and `format` field.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long live Bread King.

SavagePencil
SavagePencil previously approved these changes May 6, 2024
@@ -23,7 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `AmazonS3FileManagerDriver` for managing files on Amazon S3.
- `MediaArtifact` as a base class for `ImageArtifact` and future media Artifacts.
- Optional `exception` field to `ErrorArtifact`.
- `GriptapeCloudStructureRunClient` tool for invoking Griptape Cloud Structure Run APIs.
- `StructureRunClient` for running other Structures via a Tool.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boo but OK. In the future, we don't let consistency hold us back :)

@collindutter collindutter dismissed dylanholmes’s stale review May 6, 2024 17:13

Resolved all comments

@collindutter collindutter merged commit 0c87ea2 into dev May 6, 2024
8 checks passed
@collindutter collindutter deleted the feature/structure-run-tool branch May 6, 2024 17:13
tasks=[
StructureRunTask(
driver=LocalStructureRunDriver(
structure_factory_fn=lambda: joke_teller,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this one also return a new instance, for similar reasons to my other comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants