generated from kyegomez/Python-Package-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Oct 29, 2024
1 parent
d7ed0bd
commit 0c5d61c
Showing
14 changed files
with
788 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
# Model | ||
llm = Anthropic( | ||
model_name="claude-3-5-sonnet-20240620", | ||
temperature=0.1, | ||
) | ||
|
||
|
File renamed without changes.
Binary file added
BIN
+336 KB
...strategy_graph/business_strategy_graph_bc5a0647-84f4-45c8-a2cd-e2d5cb1ab945.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
512 changes: 512 additions & 0 deletions
512
examples/applications/business_strategy/business_strategy_graph/file.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+27.8 KB
...pplications/business_strategy/business_strategy_graph/graph_strategy_/graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48 KB
...s_strategy_graph/graph_strategy_/graph_733a6d94-68c0-48da-927e-f46b4450a173.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+102 KB
...s_strategy_graph/graph_strategy_/graph_89df5571-0c52-4f1f-86b6-d43397c052f9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+196 KB
...s_strategy_graph/graph_strategy_/graph_ae191f9d-dedf-4d62-b8cf-b9906f680afe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+196 KB
...s_strategy_graph/graph_strategy_/graph_af0e6b7d-f56b-47bc-9feb-4e4f9cc4be36.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+182 KB
...s_strategy_graph/graph_strategy_/graph_ce9625fe-aef7-4a9c-8e2d-06a274f7122d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+341 KB
.../graph_strategy_/growth_strategy_graph_1bb85379-a402-486e-a384-656dada4f84d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions
130
examples/applications/business_strategy/business_strategy_graph/growth_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
|
||
import os | ||
|
||
import mermaid as md | ||
from dotenv import load_dotenv | ||
from loguru import logger | ||
from mermaid.graph import Graph | ||
from swarm_models import OpenAIChat | ||
from swarms import Agent, extract_code_from_markdown | ||
from uuid import uuid4 | ||
|
||
load_dotenv() | ||
|
||
# Example with Groq | ||
groq_api_key = os.getenv("GROQ_API_KEY") | ||
model = OpenAIChat( | ||
openai_api_base="https://api.groq.com/openai/v1", | ||
openai_api_key=groq_api_key, | ||
model_name="llama-3.1-70b-versatile", | ||
temperature=0.1, | ||
max_tokens=4000, | ||
) | ||
|
||
GROWTH_STRATEGY_SYS_PROMPT = """ | ||
You're a hypergrowth strategist, your job is to take a business strategy for a product or company and generate a mermaid graph that outlines potential growth strategies focusing on hyper-growth opportunities using blitzscaling techniques. | ||
- **Input**: A detailed business strategy for a product or company. | ||
- **Objective**: Identify and outline potential growth strategies focusing on hyper-growth opportunities using blitzscaling techniques. | ||
- **Output**: A mermaid graph in syntax form which can be rendered in real-time. | ||
# Steps | ||
1. **Analyze**: Review the provided business strategy to understand the current position, strengths, and goals of the product or company. | ||
2. **Identify Growth Opportunities**: Utilize blitzscaling principles to pinpoint areas where rapid expansion is feasible. Consider market size, distribution channels, and technological innovations. | ||
3. **Draft Strategy Elements**: Break down the overarching growth strategy into actionable elements or nodes. These should include key tactics, potential risks, and strategic pivots. | ||
4. **Create Mermaid Graph**: Map out the identified nodes and connections, ensuring a clear narrative of the growth trajectory. Incorporate decision points, dependencies, and outcomes. | ||
# Output Format | ||
The output should be in mermaid syntax, precisely formatted to ensure it can be rendered with mermaid tools. Ensure correct use of indentation and syntax for nodes, connections, and annotations. | ||
# Example | ||
**Input**: "[Company X's strategic goal is to capture a significant share of the online education market by leveraging its existing technology platform while focusing on user acquisition, content partnerships, and international expansion.]" | ||
**Output**: | ||
``` | ||
graph TD; | ||
A[Start] --> B[Leverage Tech Platform]; | ||
B --> C[User Acquisition]; | ||
C --> D[Content Partnerships]; | ||
D --> E[International Expansion]; | ||
E --> F[Capture Market Share]; | ||
F --> G[Evaluate and Iterate]; | ||
``` | ||
(The example above should be adjusted based on the specific input company strategy, involving more nodes and potential paths.) | ||
# Notes | ||
- Ensure the strategy aligns with blitzscaling concepts: speed over efficiency, accepting risks, and focusing on winner-takes-all markets. | ||
- Consider potential roadblocks and prepare bifurcation points within the graph where strategic adjustments might be necessary. | ||
- The graph should visually narrate the strategy's progression and decision-making stages. | ||
- Maintain flexibility to accommodate additional user input and iterate upon the presented strategic model. | ||
- The interaction should support the continuous refinement of the strategy and real-time updates to the Mermaid diagram. | ||
- Only output the Mermaid graph syntax, nothing else. | ||
- Always start with the word "```mermaid" and end with "```" | ||
- Only output the Mermaid graph syntax, nothing else. | ||
- Make sure make the graph as big as possible to see all the details. | ||
""" | ||
|
||
# Initialize the agent | ||
growth_strategy_agent = Agent( | ||
agent_name="Growth-Strategy-Agent", | ||
system_prompt=GROWTH_STRATEGY_SYS_PROMPT, | ||
llm=model, | ||
max_loops=1, | ||
autosave=True, | ||
dashboard=False, | ||
verbose=True, | ||
dynamic_temperature_enabled=True, | ||
saved_state_path="growth_strategy_agent.json", | ||
user_name="swarms_corp", | ||
retry_attempts=1, | ||
context_length=200000, | ||
return_step_meta=False, | ||
output_type="string", | ||
streaming_on=False, | ||
max_tokens=4000, | ||
) | ||
|
||
|
||
|
||
def generate_growth_strategy(agent: Agent, task: str, prev_graph: str = None): | ||
""" | ||
Run the Tree of Thoughts agent and build on previous graph if provided. | ||
Args: | ||
agent (Agent): The agent to run | ||
task (str): The task to process | ||
prev_graph (str): Optional previous graph to build upon | ||
Returns: | ||
md.Mermaid: The rendered Mermaid graph | ||
""" | ||
logger.info(f"Running Tree of Thoughts agent with task: {task}") | ||
|
||
if prev_graph: | ||
# Append new graph elements to previous graph | ||
logger.debug("Building on previous graph") | ||
graph = agent.run(task + f"\nPrevious graph:\n{prev_graph}") | ||
logger.debug(f"Generated graph: {graph}") | ||
print(graph) | ||
else: | ||
logger.debug("Generating new graph") | ||
graph = agent.run(task) | ||
logger.debug(f"Generated graph: {graph}") | ||
|
||
logger.info("Rendering final Mermaid graph") | ||
graph_code = extract_code_from_markdown(graph) | ||
|
||
graph = Graph('Sequence-diagram', graph_code) | ||
render = md.Mermaid(graph, width=3800, height=3000) # Increase size to see all details | ||
render.to_png(f"growth_strategy_graph_{uuid4()}.png") # Save the graph as an image | ||
|
||
logger.info(f"Saved graph to growth_strategy_graph_{uuid4()}.png") | ||
return render | ||
|
||
|
||
generate_growth_strategy(growth_strategy_agent, "How can we grow a spreadsheet swarm product for b2b applications, it's a spreadsheet of a swarm of agents that all run concurrently. How do we grow this product ") |
145 changes: 145 additions & 0 deletions
145
examples/applications/business_strategy/business_strategy_graph/tot_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
|
||
import os | ||
|
||
import mermaid as md | ||
from dotenv import load_dotenv | ||
from loguru import logger | ||
from mermaid.graph import Graph | ||
from swarm_models import OpenAIChat | ||
from swarms import Agent, extract_code_from_markdown | ||
from uuid import uuid4 | ||
|
||
load_dotenv() | ||
|
||
# Example with Groq | ||
groq_api_key = os.getenv("GROQ_API_KEY") | ||
model = OpenAIChat( | ||
openai_api_base="https://api.groq.com/openai/v1", | ||
openai_api_key=groq_api_key, | ||
model_name="llama-3.1-70b-versatile", | ||
temperature=0.1, | ||
max_tokens=4000, | ||
) | ||
|
||
|
||
TOT_SYS_PROMPT = """ | ||
Create an agent to analyze a business strategy for a product or company and generate a Mermaid tree diagram that outlines potential paths, execution methods, risks, failures, and especially emphasizes failure scenarios. The agent should facilitate an interactive dialogue to refine and iterate upon the generated strategy model. | ||
Provide the input business strategy details to the agent, and the agent will deliver a Mermaid graph syntax that captures the strategic dynamics in real-time. | ||
# Steps | ||
1. **Strategy Analysis**: | ||
- Break down the input strategy into key components such as objectives, resources, market conditions, competitors, and operational steps. | ||
- Identify potential outcomes, paths, and decision points within the strategy. | ||
2. **Failure Identification**: | ||
- Analyze and list possible failure points in the strategy. | ||
- Emphasize these points in the Mermaid diagram. | ||
3. **Graph Construction**: | ||
- Translate the analyzed components and their relationships into a Mermaid syntax for easy visualization. | ||
- Ensure the Mermaid syntax can be rendered effectively in real-time and allows for updates based on ongoing dialogue and feedback. | ||
4. **Iterative Feedback**: | ||
- Engage in an interactive dialogue with the user to refine the business strategy. | ||
- Allow the user to input additional data, modify elements, and explore different scenarios within the graph. | ||
# Output Format | ||
The output should be in Mermaid syntax suitable for real-time rendering. Provide detailed nodes and edges to illustrate paths, key decision points, and failure emphasis. | ||
# Examples | ||
## Example 1 | ||
**Input:** | ||
Strategy: Expand market presence for Product X in international markets. | ||
**Output:** | ||
```mermaid | ||
graph LR | ||
Start[Expanding Market] | ||
A[Identify Target Markets] --> B[Assess Market Conditions] | ||
B --> C{Main Potential Issues} | ||
C -->|Logistics| D[High Costs] | ||
C -->|Regulations| E[Compliance Challenges] | ||
E -->|Failure| F[Potential Penalties] | ||
F -.->|Reassessment| Start | ||
B --> G{Success Probability} | ||
G -->|High| H[Implement Marketing Strategy] | ||
G -->|Low| C | ||
``` | ||
(Note: In real scenarios, the output will include all possible paths and failure points from the strategy described, iteratively refined in the interaction.) | ||
# Notes | ||
- Ensure that the graph highlights strategic failure points prominently. | ||
- Maintain flexibility to accommodate additional user input and iterate upon the presented strategic model. | ||
- The interaction should support the continuous refinement of the strategy and real-time updates to the Mermaid diagram. | ||
- Only output the Mermaid graph syntax, nothing else. | ||
- Always start with the word "```mermaid" and end with "```" | ||
- Only output the Mermaid graph syntax, nothing else. | ||
- Make sure make the graph as big as possible to see all the details. | ||
""" | ||
|
||
# Initialize the agent | ||
agent = Agent( | ||
agent_name="TOT-Agent", | ||
system_prompt=TOT_SYS_PROMPT, | ||
llm=model, | ||
max_loops=1, | ||
autosave=True, | ||
dashboard=False, | ||
verbose=True, | ||
dynamic_temperature_enabled=True, | ||
saved_state_path="tot_agent.json", | ||
user_name="swarms_corp", | ||
retry_attempts=1, | ||
context_length=200000, | ||
return_step_meta=False, | ||
output_type="string", | ||
streaming_on=False, | ||
max_tokens=4000, | ||
) | ||
|
||
|
||
|
||
def tree_of_thoughts_agent(agent: Agent, task: str, prev_graph: str = None): | ||
""" | ||
Run the Tree of Thoughts agent and build on previous graph if provided. | ||
Args: | ||
agent (Agent): The agent to run | ||
task (str): The task to process | ||
prev_graph (str): Optional previous graph to build upon | ||
Returns: | ||
md.Mermaid: The rendered Mermaid graph | ||
""" | ||
logger.info(f"Running Tree of Thoughts agent with task: {task}") | ||
|
||
if prev_graph: | ||
# Append new graph elements to previous graph | ||
logger.debug("Building on previous graph") | ||
graph = agent.run(task + f"\nPrevious graph:\n{prev_graph}") | ||
logger.debug(f"Generated graph: {graph}") | ||
print(graph) | ||
else: | ||
logger.debug("Generating new graph") | ||
graph = agent.run(task) | ||
logger.debug(f"Generated graph: {graph}") | ||
|
||
logger.info("Rendering final Mermaid graph") | ||
graph_code = extract_code_from_markdown(graph) | ||
|
||
graph = Graph('Sequence-diagram', graph_code) | ||
render = md.Mermaid(graph, width=3800, height=3000) # Increase size to see all details | ||
render.to_png(f"business_strategy_graph_{uuid4()}.png") | ||
|
||
logger.info(f"Saved graph to business_strategy_graph_{uuid4()}.png") | ||
return render | ||
|
||
|
||
tree_of_thoughts_agent(agent, "How can we grow a spreadsheet swarm product for b2b applications, it's a spreadsheet of a swarm of agents that all run concurrently. How do we grow this product ") |