From 09f5ef6ee9d230775e9bffa096ba9d3685fe4bea Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Fri, 12 Jul 2024 18:46:56 -0700 Subject: [PATCH] [DOCS][CLEANUP][Examples] --- README.md | 113 +++++++++++------- example.py | 2 +- .../agents/agent_with_long_term_memory.py | 36 ------ .../agent_with_longterm_memory.py | 0 .../finance_agent_with_memory | 57 +++++++++ playground/agents/first_agent_example.py | 46 +++++++ playground/agents/sales_team.py | 0 .../{ => tool_agent}/tool_agent_pydantic.py | 0 .../{ => tool_agent}/tool_agent_with_llm.py | 0 .../agent_with_basemodel_output_type.py | 0 playground/agents/{ => tools}/devin_agent.py | 0 pyproject.toml | 2 +- swarms/prompts/finance_agent_sys_prompt.py | 100 ++++++++++++++++ 13 files changed, 276 insertions(+), 80 deletions(-) delete mode 100644 playground/agents/agent_with_long_term_memory.py rename playground/agents/{ => agents_and_memory}/agent_with_longterm_memory.py (100%) create mode 100644 playground/agents/agents_and_memory/finance_agent_with_memory create mode 100644 playground/agents/first_agent_example.py delete mode 100644 playground/agents/sales_team.py rename playground/agents/{ => tool_agent}/tool_agent_pydantic.py (100%) rename playground/agents/{ => tool_agent}/tool_agent_with_llm.py (100%) rename playground/agents/{ => tools}/agent_with_basemodel_output_type.py (100%) rename playground/agents/{ => tools}/devin_agent.py (100%) create mode 100644 swarms/prompts/finance_agent_sys_prompt.py diff --git a/README.md b/README.md index 1d336e9b..a4e0cad1 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,14 @@ Features: ```python 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="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!", + 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") ), @@ -93,84 +94,110 @@ agent = Agent( verbose=True, streaming_on=True, # interactive=True, # Set to False to disable interactive mode - saved_state_path="accounting_agent.json", - # tools=[ - # # calculate_profit, - # # generate_report, - # # search_knowledge_base, - # # write_memory_to_rag, - # # search_knowledge_base, - # # generate_speech, - # ], - stopping_token="Stop!", - interactive=True, - # docs_folder="docs", - # pdf_path="docs/accounting_agent.pdf", + 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="User", + user_name="swarms_corp", # # docs= # # docs_folder="docs", - # retry_attempts=3, + retry_attempts=3, # context_length=1000, # tool_schema = dict - context_length=1000, + context_length=200000, # agent_ops_on=True, # long_term_memory=ChromaDB(docs_folder="artifacts"), ) + +contract = data_to_text("your_contract_pdf.pdf") + 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. ```python import os -from dotenv import load_dotenv -from swarms import Agent, OpenAIChat -from swarms_memory import ChromaDB -# Get the API key from the environment -api_key = os.environ.get("OPENAI_API_KEY") +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="scp", - docs_folder="artifacts", + output_dir="fiance_agent_rag", + # 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( +<<<<<<< HEAD llm=llm, agent_name = "WellNess Agent", system_prompt="Generate a 10,000 word blog on health and wellness.", 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, - dashboard=True, - long_term_memory=chromadb, - memory_chunk_size=300, + # 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"), ) -# 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! 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", ) -# Tools +# Tools in swarms are simple python functions and docstrings def terminal( code: str, ): @@ -284,6 +311,8 @@ print(out) ``` +------- + ### Devin Implementation of Devin in less than 90 lines of code with several tools: diff --git a/example.py b/example.py index cbd34051..ebe4763b 100644 --- a/example.py +++ b/example.py @@ -1,6 +1,6 @@ -from swarms import Agent, Anthropic import os +from swarms import Agent, Anthropic # Initialize the agent agent = Agent( diff --git a/playground/agents/agent_with_long_term_memory.py b/playground/agents/agent_with_long_term_memory.py deleted file mode 100644 index d8fc2861..00000000 --- a/playground/agents/agent_with_long_term_memory.py +++ /dev/null @@ -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") diff --git a/playground/agents/agent_with_longterm_memory.py b/playground/agents/agents_and_memory/agent_with_longterm_memory.py similarity index 100% rename from playground/agents/agent_with_longterm_memory.py rename to playground/agents/agents_and_memory/agent_with_longterm_memory.py diff --git a/playground/agents/agents_and_memory/finance_agent_with_memory b/playground/agents/agents_and_memory/finance_agent_with_memory new file mode 100644 index 00000000..4064b303 --- /dev/null +++ b/playground/agents/agents_and_memory/finance_agent_with_memory @@ -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}" +) diff --git a/playground/agents/first_agent_example.py b/playground/agents/first_agent_example.py new file mode 100644 index 00000000..efd4310f --- /dev/null +++ b/playground/agents/first_agent_example.py @@ -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}" +) diff --git a/playground/agents/sales_team.py b/playground/agents/sales_team.py deleted file mode 100644 index e69de29b..00000000 diff --git a/playground/agents/tool_agent_pydantic.py b/playground/agents/tool_agent/tool_agent_pydantic.py similarity index 100% rename from playground/agents/tool_agent_pydantic.py rename to playground/agents/tool_agent/tool_agent_pydantic.py diff --git a/playground/agents/tool_agent_with_llm.py b/playground/agents/tool_agent/tool_agent_with_llm.py similarity index 100% rename from playground/agents/tool_agent_with_llm.py rename to playground/agents/tool_agent/tool_agent_with_llm.py diff --git a/playground/agents/agent_with_basemodel_output_type.py b/playground/agents/tools/agent_with_basemodel_output_type.py similarity index 100% rename from playground/agents/agent_with_basemodel_output_type.py rename to playground/agents/tools/agent_with_basemodel_output_type.py diff --git a/playground/agents/devin_agent.py b/playground/agents/tools/devin_agent.py similarity index 100% rename from playground/agents/devin_agent.py rename to playground/agents/tools/devin_agent.py diff --git a/pyproject.toml b/pyproject.toml index bbccb931..36ac61f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "5.3.4" +version = "5.3.5" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/prompts/finance_agent_sys_prompt.py b/swarms/prompts/finance_agent_sys_prompt.py new file mode 100644 index 00000000..5f3358dc --- /dev/null +++ b/swarms/prompts/finance_agent_sys_prompt.py @@ -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. + +"""