[DOCS][CLEANUP][Examples]

pull/535/head
Kye Gomez 6 months ago
parent 6fc1ecf5bb
commit 09f5ef6ee9

@ -76,13 +76,14 @@ Features:
```python ```python
import os import os
from swarms import Agent, Anthropic from swarms import Agent, Anthropic
from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT
from swarms.utils.data_to_text import data_to_text
# Initialize the agent # Initialize the agent
agent = Agent( agent = Agent(
agent_name="Accounting Assistant", agent_name="Financial-Analysis-Agent",
system_prompt="You're the accounting agent, your purpose is to generate a profit report for a company!", system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
agent_description="Generate a profit report for a company!", agent_description="Agent creates ",
llm=Anthropic( llm=Anthropic(
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY") anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
), ),
@ -93,84 +94,110 @@ agent = Agent(
verbose=True, verbose=True,
streaming_on=True, streaming_on=True,
# interactive=True, # Set to False to disable interactive mode # interactive=True, # Set to False to disable interactive mode
saved_state_path="accounting_agent.json", dynamic_temperature_enabled=True,
# tools=[ saved_state_path="finance_agent.json",
# # calculate_profit, # tools=[Add your functions here# ],
# # generate_report, # stopping_token="Stop!",
# # search_knowledge_base, # interactive=True,
# # write_memory_to_rag, # docs_folder="docs", # Enter your folder name
# # search_knowledge_base, # pdf_path="docs/finance_agent.pdf",
# # generate_speech,
# ],
stopping_token="Stop!",
interactive=True,
# docs_folder="docs",
# pdf_path="docs/accounting_agent.pdf",
# sop="Calculate the profit for a company.", # sop="Calculate the profit for a company.",
# sop_list=["Calculate the profit for a company."], # sop_list=["Calculate the profit for a company."],
# user_name="User", user_name="swarms_corp",
# # docs= # # docs=
# # docs_folder="docs", # # docs_folder="docs",
# retry_attempts=3, retry_attempts=3,
# context_length=1000, # context_length=1000,
# tool_schema = dict # tool_schema = dict
context_length=1000, context_length=200000,
# agent_ops_on=True, # agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"), # long_term_memory=ChromaDB(docs_folder="artifacts"),
) )
contract = data_to_text("your_contract_pdf.pdf")
agent.run( agent.run(
"Search the knowledge base for the swarms github framework and how it works" f"Analyze the following contract and give me a full summary: {contract}"
) )
``` ```
-----
### `Agent` + Long Term Memory ### Agent with RAG
`Agent` equipped with quasi-infinite long term memory. Great for long document understanding, analysis, and retrieval. `Agent` equipped with quasi-infinite long term memory. Great for long document understanding, analysis, and retrieval.
```python ```python
import os import os
from dotenv import load_dotenv
from swarms import Agent, OpenAIChat
from swarms_memory import ChromaDB
# Get the API key from the environment from swarms_memory import ChromaDB
api_key = os.environ.get("OPENAI_API_KEY")
from swarms import Agent, Anthropic
from swarms.prompts.finance_agent_sys_prompt import (
FINANCIAL_AGENT_SYS_PROMPT,
)
from swarms.utils.data_to_text import data_to_text
# Initilaize the chromadb client # Initilaize the chromadb client
chromadb = ChromaDB( chromadb = ChromaDB(
metric="cosine", metric="cosine",
output_dir="scp", output_dir="fiance_agent_rag",
docs_folder="artifacts", # docs_folder="artifacts", # Folder of your documents
) )
# Initialize the language model
llm = OpenAIChat(
temperature=0.5,
openai_api_key=api_key,
max_tokens=1000,
)
## Initialize the workflow # Initialize the agent
agent = Agent( agent = Agent(
<<<<<<< HEAD
llm=llm, llm=llm,
agent_name = "WellNess Agent", agent_name = "WellNess Agent",
system_prompt="Generate a 10,000 word blog on health and wellness.", system_prompt="Generate a 10,000 word blog on health and wellness.",
max_loops=4, max_loops=4,
=======
agent_name="Financial-Analysis-Agent",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
agent_description="Agent creates ",
llm=Anthropic(anthropic_api_key=os.getenv("ANTHROPIC_API_KEY")),
max_loops="auto",
>>>>>>> e0f65ebc ([DOCS][CLEANUP][Examples])
autosave=True, autosave=True,
dashboard=True, # dynamic_temperature_enabled=True,
long_term_memory=chromadb, dashboard=False,
memory_chunk_size=300, verbose=True,
streaming_on=True,
# interactive=True, # Set to False to disable interactive mode
dynamic_temperature_enabled=True,
saved_state_path="finance_agent.json",
# tools=[Add your functions here# ],
# stopping_token="Stop!",
# interactive=True,
# docs_folder="docs", # Enter your folder name
# pdf_path="docs/finance_agent.pdf",
# sop="Calculate the profit for a company.",
# sop_list=["Calculate the profit for a company."],
user_name="swarms_corp",
# # docs=
# # docs_folder="docs",
retry_attempts=3,
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
) )
# Run the workflow on a task
agent.run("Generate a 10,000 word blog on health and wellness.") contract = data_to_text("your_contract_pdf.pdf")
agent.run(
f"Analyze the following contract and give me a full summary: {contract}"
)
``` ```
-------
### `Agent` ++ Long Term Memory ++ Tools! ### `Agent` ++ Long Term Memory ++ Tools!
An LLM equipped with long term memory and tools, a full stack agent capable of automating all and any digital tasks given a good prompt. An LLM equipped with long term memory and tools, a full stack agent capable of automating all and any digital tasks given a good prompt.
@ -190,7 +217,7 @@ memory = ChromaDB(
docs_folder="docs", docs_folder="docs",
) )
# Tools # Tools in swarms are simple python functions and docstrings
def terminal( def terminal(
code: str, code: str,
): ):
@ -284,6 +311,8 @@ print(out)
``` ```
-------
### Devin ### Devin
Implementation of Devin in less than 90 lines of code with several tools: Implementation of Devin in less than 90 lines of code with several tools:

@ -1,6 +1,6 @@
from swarms import Agent, Anthropic
import os import os
from swarms import Agent, Anthropic
# Initialize the agent # Initialize the agent
agent = Agent( agent = Agent(

@ -1,36 +0,0 @@
from swarms import Agent, OpenAIChat
from swarms_memory import ChromaDB
from swarms.models.tiktoken_wrapper import TikTokenizer
# Initialize the agent
agent = Agent(
agent_name="Accounting Assistant",
system_prompt="You're the accounting agent, your purpose is to generate a profit report for a company!",
agent_description="Generate a profit report for a company!",
llm=OpenAIChat(),
max_loops=1,
autosave=True,
# dynamic_temperature_enabled=True,
dashboard=False,
verbose=True,
streaming_on=True,
# interactive=True, # Set to False to disable interactive mode
# docs_folder="docs",
# pdf_path="docs/accounting_agent.pdf",
# sop="Calculate the profit for a company.",
# sop_list=["Calculate the profit for a company."],
# user_name="User",
# # docs=
# # docs_folder="docs",
# retry_attempts=3,
# context_length=1000,
# tool_schema = dict
context_length=1000,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
long_term_memory=ChromaDB(
docs_folder="artifacts", output_dir="test", n_results=1
),
tokenizer=TikTokenizer(),
)
agent.run("Whats the best agent available for accounting")

@ -0,0 +1,57 @@
import os
from swarms_memory import ChromaDB
from swarms import Agent, Anthropic
from swarms.prompts.finance_agent_sys_prompt import (
FINANCIAL_AGENT_SYS_PROMPT,
)
from swarms.utils.data_to_text import data_to_text
# Initilaize the chromadb client
chromadb = ChromaDB(
metric="cosine",
output_dir="fiance_agent_rag",
# docs_folder="artifacts", # Folder of your documents
)
# Initialize the agent
agent = Agent(
agent_name="Financial-Analysis-Agent",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
agent_description="Agent creates ",
llm=Anthropic(anthropic_api_key=os.getenv("ANTHROPIC_API_KEY")),
max_loops="auto",
autosave=True,
# dynamic_temperature_enabled=True,
dashboard=False,
verbose=True,
streaming_on=True,
# interactive=True, # Set to False to disable interactive mode
dynamic_temperature_enabled=True,
saved_state_path="finance_agent.json",
# tools=[Add your functions here# ],
# stopping_token="Stop!",
# interactive=True,
# docs_folder="docs", # Enter your folder name
# pdf_path="docs/finance_agent.pdf",
# sop="Calculate the profit for a company.",
# sop_list=["Calculate the profit for a company."],
user_name="swarms_corp",
# # docs=
# # docs_folder="docs",
retry_attempts=3,
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)
contract = data_to_text("your_contract_pdf.pdf")
agent.run(
f"Analyze the following contract and give me a full summary: {contract}"
)

@ -0,0 +1,46 @@
import os
from swarms import Agent, Anthropic
from swarms.prompts.finance_agent_sys_prompt import (
FINANCIAL_AGENT_SYS_PROMPT,
)
from swarms.utils.data_to_text import data_to_text
# Initialize the agent
agent = Agent(
agent_name="Financial-Analysis-Agent",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
agent_description="Agent creates ",
llm=Anthropic(anthropic_api_key=os.getenv("ANTHROPIC_API_KEY")),
max_loops="auto",
autosave=True,
# dynamic_temperature_enabled=True,
dashboard=False,
verbose=True,
streaming_on=True,
# interactive=True, # Set to False to disable interactive mode
dynamic_temperature_enabled=True,
saved_state_path="finance_agent.json",
# tools=[Add your functions here# ],
# stopping_token="Stop!",
# interactive=True,
# docs_folder="docs", # Enter your folder name
# pdf_path="docs/finance_agent.pdf",
# sop="Calculate the profit for a company.",
# sop_list=["Calculate the profit for a company."],
user_name="swarms_corp",
# # docs=
# # docs_folder="docs",
retry_attempts=3,
# context_length=1000,
# tool_schema = dict
context_length=200000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)
contract = data_to_text("your_contract_pdf.pdf")
agent.run(
f"Analyze the following contract and give me a full summary: {contract}"
)

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "5.3.4" version = "5.3.5"
description = "Swarms - Pytorch" description = "Swarms - Pytorch"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"] authors = ["Kye Gomez <kye@apac.ai>"]

@ -0,0 +1,100 @@
FINANCIAL_AGENT_SYS_PROMPT = """
### System Prompt for an Agent Specializing in Analyzing Financial and Accounting Statements
---
#### Introduction
Welcome! You are an advanced AI agent designed to analyze financial and accounting statements, extracting and summarizing key statistics and insights. Your primary goal is to provide structured knowledge that highlights the financial health, performance, and trends within an organization. Below, we will detail how you should approach this task, including how to think, reason, and structure your analyses, followed by several examples to illustrate the process.
#### How to Think and Reason
1. **Understand the Document:**
- Begin by identifying the type of financial statement you are analyzing. Common types include balance sheets, income statements, cash flow statements, and statements of shareholders' equity.
- Determine the reporting period and the currency used.
2. **Identify Key Sections:**
- For balance sheets, focus on assets, liabilities, and shareholders' equity.
- For income statements, focus on revenues, expenses, and net income.
- For cash flow statements, focus on operating, investing, and financing activities.
- For statements of shareholders' equity, focus on changes in equity, including retained earnings and issued shares.
3. **Extract Key Metrics:**
- Calculate and highlight important financial ratios such as liquidity ratios (current ratio, quick ratio), profitability ratios (gross profit margin, net profit margin, return on equity), and solvency ratios (debt-to-equity ratio, interest coverage ratio).
- Identify trends by comparing current figures with those from previous periods.
- Highlight significant changes, unusual items, and potential red flags.
4. **Summarize Clearly and Concisely:**
- Use plain language to explain the financial health and performance of the organization.
- Organize your summary logically, mirroring the structure of the original document.
- Include visual aids like charts or graphs where applicable to illustrate trends and comparisons.
#### Examples
---
**Example 1: Income Statement Analysis**
**Original Text:**
"ABC Corporation's income statement for the fiscal year ended December 31, 2023, reports total revenues of $5,000,000, cost of goods sold (COGS) of $3,000,000, operating expenses of $1,200,000, and net income of $600,000. The previous fiscal year's total revenues were $4,500,000, with a net income of $500,000."
**Summary:**
- **Revenues:** $5,000,000 (up from $4,500,000 in the previous year, an increase of 11.1%)
- **Cost of Goods Sold (COGS):** $3,000,000
- **Operating Expenses:** $1,200,000
- **Net Income:** $600,000 (up from $500,000 in the previous year, an increase of 20%)
- **Gross Profit Margin:** 40% (calculated as (Revenues - COGS) / Revenues)
- **Net Profit Margin:** 12% (calculated as Net Income / Revenues)
- **Key Observations:** Revenue growth of 11.1%, with a significant improvement in net income (20% increase), indicating improved profitability.
---
**Example 2: Balance Sheet Analysis**
**Original Text:**
"As of December 31, 2023, XYZ Ltd.'s balance sheet reports total assets of $10,000,000, total liabilities of $6,000,000, and shareholders' equity of $4,000,000. The previous year's total assets were $9,000,000, total liabilities were $5,500,000, and shareholders' equity was $3,500,000."
**Summary:**
- **Total Assets:** $10,000,000 (up from $9,000,000 in the previous year, an increase of 11.1%)
- **Total Liabilities:** $6,000,000 (up from $5,500,000 in the previous year, an increase of 9.1%)
- **Shareholders' Equity:** $4,000,000 (up from $3,500,000 in the previous year, an increase of 14.3%)
- **Current Ratio:** 1.67 (calculated as Total Assets / Total Liabilities)
- **Debt-to-Equity Ratio:** 1.5 (calculated as Total Liabilities / Shareholders' Equity)
- **Key Observations:** Healthy increase in both assets and equity, indicating growth and improved financial stability. The debt-to-equity ratio suggests a moderate level of debt relative to equity.
---
**Example 3: Cash Flow Statement Analysis**
**Original Text:**
"For the fiscal year ended December 31, 2023, DEF Inc.'s cash flow statement shows net cash provided by operating activities of $700,000, net cash used in investing activities of $300,000, and net cash used in financing activities of $200,000. The beginning cash balance was $100,000, and the ending cash balance was $300,000."
**Summary:**
- **Net Cash Provided by Operating Activities:** $700,000
- **Net Cash Used in Investing Activities:** $300,000
- **Net Cash Used in Financing Activities:** $200,000
- **Net Increase in Cash:** $200,000 (calculated as $700,000 - $300,000 - $200,000)
- **Beginning Cash Balance:** $100,000
- **Ending Cash Balance:** $300,000
- **Key Observations:** Positive cash flow from operating activities indicates strong operational performance. The company is investing in growth while maintaining a healthy cash balance. The ending cash balance shows a significant increase, indicating improved liquidity.
---
**Example 4: Statement of Shareholders' Equity Analysis**
**Original Text:**
"GHI Corporation's statement of shareholders' equity for the fiscal year ended December 31, 2023, shows common stock of $1,000,000, retained earnings of $2,000,000, and additional paid-in capital of $500,000. The previous year's retained earnings were $1,500,000."
**Summary:**
- **Common Stock:** $1,000,000
- **Retained Earnings:** $2,000,000 (up from $1,500,000 in the previous year, an increase of 33.3%)
- **Additional Paid-in Capital:** $500,000
- **Total Shareholders' Equity:** $3,500,000
- **Key Observations:** Significant growth in retained earnings indicates strong profitability and reinvestment in the business. The overall increase in shareholders' equity reflects the company's robust financial health and potential for future growth.
---
By following this structured approach, you will be able to provide thorough and accurate analyses of financial and accounting statements, ensuring that all key metrics and insights are clearly understood.
"""
Loading…
Cancel
Save