Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed May 6, 2024
1 parent 0196143 commit 9bbbfd3
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 119 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Optional `exception` field to `ErrorArtifact`.
- `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.
- `LocalStructureRunDriver` for running Structures in the same runtime environment as the code that is running the Structure.
- `GriptapeCloudStructureRunDriver` for running Structures in Griptape Cloud.
- `LocalStructureRunDriver` for running Structures in the same run-time environment as the code that is running the Structure.

### Changed
- **BREAKING**: Secret fields (ex: api_key) removed from serialized Drivers.
Expand All @@ -37,7 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING**: `FileManager.default_loader` is now `None` by default.
- **BREAKING** Bumped `pinecone` from `^2` to `^3`.
- **BREAKING**: Removed `workdir`, `loaders`, `default_loader`, and `save_file_encoding` fields from `FileManager` and added `file_manager_driver`.
- **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.
- Improved RAG performance in `VectorQueryEngine`.
- Moved [Griptape Docs](https://github.com/griptape-ai/griptape-docs) to this repository.
- Updated `EventListener.handler`'s behavior so that the return value will be passed to the `EventListenerDriver.try_publish_event_payload`'s `event_payload` parameter.
Expand Down
33 changes: 20 additions & 13 deletions docs/examples/multi-agent-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ Additionally, this architecture opens us up to using services such as [Griptape

```python
import os
from pathlib import Path

from griptape.drivers import WebhookEventListenerDriver
from griptape.drivers import WebhookEventListenerDriver, LocalStructureRunDriver
from griptape.events import EventListener, FinishStructureRunEvent
from griptape.rules import Rule, Ruleset
from griptape.structures import Agent, Workflow
Expand All @@ -23,13 +22,13 @@ WRITERS = [
{
"role": "Travel Adventure Blogger",
"goal": "Inspire wanderlust with stories of hidden gems and exotic locales",
"backstory": "With a passport full of stamps, you bring distant cultures and breathtaking scenes to life through vivid storytelling and personal anecdotes."
"backstory": "With a passport full of stamps, you bring distant cultures and breathtaking scenes to life through vivid storytelling and personal anecdotes.",
},
{
"role": "Lifestyle Freelance Writer",
"goal": "Share practical advice on living a balanced and stylish life",
"backstory": "From the latest trends in home decor to tips for wellness, your articles help readers create a life that feels both aspirational and attainable."
}
"backstory": "From the latest trends in home decor to tips for wellness, your articles help readers create a life that feels both aspirational and attainable.",
},
]


Expand Down Expand Up @@ -147,10 +146,14 @@ if __name__ == "__main__":
team = Workflow()
research_task = team.add_task(
StructureRunTask(
"""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.""",
(
"""Perform a detailed examination of the newest developments in AI as of 2024.
Pinpoint major trends, breakthroughs, and their implications for various industries.""",
),
id="research",
target_structure=build_researcher(),
driver=LocalStructureRunDriver(
structure_factory_fn=build_researcher,
),
),
)
end_task = team.add_task(
Expand All @@ -162,17 +165,21 @@ if __name__ == "__main__":
research_task,
[
StructureRunTask(
"""Using insights provided, develop an engaging blog
(
"""Using insights provided, develop an engaging blog
post that highlights the most significant AI advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Make it sound cool, avoid complex words so it doesn't sound like AI.
Insights:
{{ parent_outputs["research"] }}""",
target_structure=build_writer(
role=writer["role"],
goal=writer["goal"],
backstory=writer["backstory"],
),
driver=LocalStructureRunDriver(
structure_factory_fn=lambda: build_writer(
role=writer["role"],
goal=writer["goal"],
backstory=writer["backstory"],
)
),
)
for writer in WRITERS
Expand Down
6 changes: 3 additions & 3 deletions docs/griptape-framework/drivers/structure-run-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ joke_coordinator = Pipeline(
),
),
StructureRunTask(
"Rewrite this joke: {{ parent_output }}",
("Rewrite this joke: {{ parent_output }}",),
driver=LocalStructureRunDriver(
structure_factory_fn=lambda: joke_rewriter,
),
Expand Down Expand Up @@ -68,7 +68,7 @@ structure_id = os.environ["GRIPTAPE_CLOUD_STRUCTURE_ID"]
pipeline = Pipeline(
tasks=[
StructureRunTask(
"Think of a question related to Retrieval Augmented Generation.",
("Think of a question related to Retrieval Augmented Generation.",),
driver=LocalStructureRunDriver(
structure=Agent(
rules=[
Expand All @@ -83,7 +83,7 @@ pipeline = Pipeline(
),
),
StructureRunTask(
"{{ parent_output }}",
("{{ parent_output }}",),
driver=GriptapeCloudStructureRunDriver(
base_url=base_url,
api_key=api_key,
Expand Down
204 changes: 104 additions & 100 deletions docs/griptape-framework/structures/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,118 +685,122 @@ from griptape.tools import (
WebSearch,
)

researcher = Agent(
tools=[
WebSearch(
google_api_key=os.environ["GOOGLE_API_KEY"],
google_api_search_id=os.environ["GOOGLE_API_SEARCH_ID"],
off_prompt=False,
),
WebScraper(
off_prompt=True,
),
TaskMemoryClient(off_prompt=False),
],
rulesets=[
Ruleset(
name="Position",
rules=[
Rule(
value="Senior Research Analyst",
)
],
),
Ruleset(
name="Objective",
rules=[
Rule(
value="Uncover cutting-edge developments in AI and data science",
)
],
),
Ruleset(
name="Background",
rules=[
Rule(
value="""You work at a leading tech think tank.,
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights."""
)
],
),
Ruleset(
name="Desired Outcome",
rules=[
Rule(
value="Full analysis report in bullet points",
)
],
),
],
)

writer = Agent(
input_template="Instructions: {{args[0]}}\nContext: {{args[1]}}",
rulesets=[
Ruleset(
name="Position",
rules=[
Rule(
value="Tech Content Strategist",
)
],
),
Ruleset(
name="Objective",
rules=[
Rule(
value="Craft compelling content on tech advancements",
)
],
),
Ruleset(
name="Backstory",
rules=[
Rule(
value="""You are a renowned Content Strategist, known for your insightful and engaging articles.
You transform complex concepts into compelling narratives."""
)
],
),
Ruleset(
name="Desired Outcome",
rules=[
Rule(
value="Full blog post of at least 4 paragraphs",
)
],
),
],
)
def build_researcher():
researcher = Agent(
tools=[
WebSearch(
google_api_key=os.environ["GOOGLE_API_KEY"],
google_api_search_id=os.environ["GOOGLE_API_SEARCH_ID"],
off_prompt=False,
),
WebScraper(
off_prompt=True,
),
TaskMemoryClient(off_prompt=False),
],
rulesets=[
Ruleset(
name="Position",
rules=[
Rule(
value="Senior Research Analyst",
)
],
),
Ruleset(
name="Objective",
rules=[
Rule(
value="Uncover cutting-edge developments in AI and data science",
)
],
),
Ruleset(
name="Background",
rules=[
Rule(
value="""You work at a leading tech think tank.,
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights."""
)
],
),
Ruleset(
name="Desired Outcome",
rules=[
Rule(
value="Full analysis report in bullet points",
)
],
),
],
)

return researcher


def build_writer():
writer = Agent(
input_template="Instructions: {{args[0]}}\nContext: {{args[1]}}",
rulesets=[
Ruleset(
name="Position",
rules=[
Rule(
value="Tech Content Strategist",
)
],
),
Ruleset(
name="Objective",
rules=[
Rule(
value="Craft compelling content on tech advancements",
)
],
),
Ruleset(
name="Backstory",
rules=[
Rule(
value="""You are a renowned Content Strategist, known for your insightful and engaging articles.
You transform complex concepts into compelling narratives."""
)
],
),
Ruleset(
name="Desired Outcome",
rules=[
Rule(
value="Full blog post of at least 4 paragraphs",
)
],
),
],
)

return writer


team = Pipeline(
tasks=[
StructureRunTask(
(
"""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.""",
),
driver=LocalStructureRunDriver(
structure_factory_fn=lambda: researcher,
"""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(structure_factory_fn=build_researcher),
),
StructureRunTask(
(
"""Using insights provided, develop an engaging blog
post that highlights the most significant AI advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Make it sound cool, avoid complex words so it doesn't sound like AI.
""",
"""Utilize the gathered insights to craft a captivating blog
article showcasing the key AI innovations.
Ensure the content is engaging yet straightforward, appealing to a tech-aware readership.
Keep the tone appealing and use simple language to make it less technical.""",
"{{parent_output}}",
),
driver=LocalStructureRunDriver(
structure_factory_fn=lambda: writer,
),
driver=LocalStructureRunDriver(structure_factory_fn=build_writer),
),
],
)
Expand Down

0 comments on commit 9bbbfd3

Please sign in to comment.