From 846b8bb1e816ed03abeb9e353fd5c1975dce92eb Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Thu, 25 Jul 2024 15:37:20 -0400 Subject: [PATCH] [AGENTS][EXAMPLES] --- .gitignore | 1 + agent_with_basemodel_output_type.py | 5 +- docs/mkdocs.yml | 7 +- docs/swarms/framework/vision.md | 167 ++++++++++++++++++ playground/agents/estate_planning_agent.py | 122 +++++++++++++ .../financial_agent_gpt4o_mini.py | 7 +- 6 files changed, 300 insertions(+), 9 deletions(-) create mode 100644 docs/swarms/framework/vision.md create mode 100644 playground/agents/estate_planning_agent.py rename playground/agents/{gpt4o_mini_demo => }/financial_agent_gpt4o_mini.py (89%) diff --git a/.gitignore b/.gitignore index 2c252f38c..82e7f4b5b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ dataframe/ static/generated runs +Financial-Analysis-Agent_state.json artifacts_five chroma Accounting Assistant_state.json diff --git a/agent_with_basemodel_output_type.py b/agent_with_basemodel_output_type.py index f53b31324..409ceef02 100644 --- a/agent_with_basemodel_output_type.py +++ b/agent_with_basemodel_output_type.py @@ -1,6 +1,7 @@ from pydantic import BaseModel, Field from swarms import OpenAIChat from swarms import Agent +import os # Initialize the schema for the person's information @@ -32,7 +33,9 @@ class Schema(BaseModel): ), # Set the tool schema to the JSON string -- this is the key difference # tool_schema=tool_schema, - llm=OpenAIChat(), + llm=OpenAIChat( + openai_api_key=os.getenv("OPENAI_API_KEY"), + ), max_loops=3, autosave=True, dashboard=False, diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index dd22e9d04..49f71cc58 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -129,6 +129,7 @@ nav: - Contributing: "contributing.md" - Multi-Agent Repository Template: "swarms/install/multi_agent_template.md" - Swarm Ecosystem: "swarms/ecosystem.md" + - The Vision: "swarms/vision.md" - Framework: - Overview: "swarms/framework/index.md" - Models: @@ -153,7 +154,7 @@ nav: - Models: - How to Create A Custom Language Model: "swarms/models/custom_model.md" - Models Available: "swarms/models/index.md" - - MultiModal Models Available: "swarms/models/multimodal_models.md" + - Multi Modal Models Available: "swarms/models/multimodal_models.md" - Language Models: - BaseLLM: "swarms/models/base_llm.md" - HuggingFaceLLM: "swarms/models/huggingface.md" @@ -211,9 +212,7 @@ nav: - Memory Systems: - ChromaDB: "swarms_memory/chromadb.md" - Pinecone: "swarms_memory/pinecone.md" - # - Redis: "swarms_memory/redis.md" - Faiss: "swarms_memory/faiss.md" - # - HNSW: "swarms_memory/hnsw.md" - Swarms Platform: - Overview: "swarms_platform/index.md" - Prompts API: "swarms_platform/prompts_api.md" @@ -221,4 +220,4 @@ nav: - Comparing LLM Provider Pricing A Guide for Enterprises: "guides/pricing.md" - References: - Agent Glossary: "swarms/glossary.md" - - List of The Best Multi-Agent Papers: "swarms/papers.md" + - List of The Best Multi-Agent Papers: "swarms/papers.md" \ No newline at end of file diff --git a/docs/swarms/framework/vision.md b/docs/swarms/framework/vision.md new file mode 100644 index 000000000..cc607b293 --- /dev/null +++ b/docs/swarms/framework/vision.md @@ -0,0 +1,167 @@ +### Swarms Vision + +**Swarms** is dedicated to transforming enterprise automation by offering a robust and intuitive interface for multi-agent collaboration and seamless integration with multiple models. Our mission is to enable enterprises to enhance their operational efficiency and effectiveness through intelligent automation. + +#### Vision Statement + +**To become the preeminent framework for orchestrating multi-agent collaboration and integration, empowering enterprises to achieve exceptional automation efficiency and operational excellence.** + +#### Core Principles + +1. **Multi-Agent Collaboration**: Facilitate seamless collaboration between diverse agents to solve complex and dynamic problems. +2. **Integration**: Provide robust and flexible integration with various models and frameworks to maximize functionality. +3. **Enterprise Automation**: Deliver enterprise-grade solutions designed for reliability, scalability, and security. +4. **Open Ecosystem**: Promote an open and extensible ecosystem that encourages innovation, community engagement, and collaborative development. + +### Vision Document with Mermaid Graphs + +#### Overview Diagram + +```mermaid +graph TD + A[Swarms Framework] --> B[Multi-Agent Collaboration] + A --> C[Integration with Multiple Models] + A --> D[Enterprise Automation] + A --> E[Open Ecosystem] + + B --> F[Seamless Communication] + B --> G[Collaboration Protocols] + + C --> H[Model Integration] + C --> I[Framework Compatibility] + + D --> J[Operational Efficiency] + D --> K[Reliability and Scalability] + + E --> L[Encourage Innovation] + E --> M[Community Driven] +``` + +#### Multi-Agent Collaboration + +```mermaid +graph TD + B[Multi-Agent Collaboration] --> F[Seamless Communication] + B --> G[Collaboration Protocols] + + F --> N[Cross-Agent Messaging] + F --> O[Task Coordination] + F --> P[Real-Time Updates] + + G --> Q[Standard APIs] + G --> R[Extensible Protocols] + G --> S[Security and Compliance] + + N --> T[Agent Messaging Hub] + O --> U[Task Assignment and Monitoring] + P --> V[Instantaneous Data Sync] + + Q --> W[Unified API Interface] + R --> X[Customizable Protocols] + S --> Y[Compliance with Standards] + S --> Z[Secure Communication Channels] +``` + +#### Integration with Multiple Models + +```mermaid +graph TD + C[Integration with Multiple Models] --> H[Model Integration] + C --> I[Framework Compatibility] + + H --> R[Plug-and-Play Models] + H --> S[Model Orchestration] + H --> T[Model Versioning] + + I --> U[Support for OpenAI] + I --> V[Support for Anthropic] + I --> W[Support for Gemini] + I --> X[Support for LangChain] + I --> Y[Support for AutoGen] + I --> Z[Support for Custom Models] + + R --> AA[Easy Model Integration] + S --> AB[Dynamic Model Orchestration] + T --> AC[Version Control] + + U --> AD[Integration with OpenAI Models] + V --> AE[Integration with Anthropic Models] + W --> AF[Integration with Gemini Models] + X --> AG[Integration with LangChain Models] + Y --> AH[Integration with AutoGen Models] + Z --> AI[Support for Proprietary Models] +``` + +#### Enterprise Automation + +```mermaid +graph TD + D[Enterprise Automation] --> J[Operational Efficiency] + D --> K[Reliability and Scalability] + + J --> Y[Automate Workflows] + J --> Z[Reduce Manual Work] + J --> AA[Increase Productivity] + + K --> AB[High Uptime] + K --> AC[Enterprise-Grade Security] + K --> AD[Scalable Solutions] + + Y --> AE[Workflow Automation Tools] + Z --> AF[Eliminate Redundant Tasks] + AA --> AG[Boost Employee Efficiency] + + AB --> AH[Robust Infrastructure] + AC --> AI[Security Compliance] + AD --> AJ[Scale with Demand] +``` + +#### Open Ecosystem + +```mermaid +graph TD + E[Open Ecosystem] --> L[Encourage Innovation] + E --> M[Community Driven] + + L --> AC[Open Source Contributions] + L --> AD[Hackathons and Workshops] + L --> AE[Research and Development] + + M --> AF[Active Community Support] + M --> AG[Collaborative Development] + M --> AH[Shared Resources] + + AC --> AI[Community Contributions] + AD --> AJ[Innovative Events] + AE --> AK[Continuous R&D] + + AF --> AL[Supportive Community] + AG --> AM[Joint Development Projects] + AH --> AN[Shared Knowledge Base] +``` + +--- + +### Detailed Breakdown + +#### Multi-Agent Collaboration + +Swarms excels in enabling seamless communication and coordination between multiple agents, fostering a collaborative environment where agents can work together to solve complex tasks. Our platform supports cross-agent messaging, task coordination, and real-time updates, ensuring that all agents are synchronized and can efficiently contribute to the collective goal. + +#### Integration with Multiple Models + +Swarms provides robust integration capabilities with a wide array of models, including OpenAI, Anthropic, Gemini, LangChain, AutoGen, and custom models. This ensures that enterprises can leverage the best models available to meet their specific needs, while also allowing for dynamic model orchestration and version control to keep operations up-to-date and effective. + +#### Enterprise Automation + +Our framework is designed to enhance operational efficiency through automation. By automating workflows, reducing manual work, and increasing productivity, Swarms helps enterprises achieve higher efficiency and operational excellence. Our solutions are built for high uptime, enterprise-grade security, and scalability, ensuring reliable and secure operations. + +#### Open Ecosystem + +Swarms promotes an open and extensible ecosystem, encouraging community-driven innovation and development. We support open-source contributions, organize hackathons and workshops, and continuously invest in research and development. Our active community fosters collaborative development, shared resources, and a supportive environment for innovation. + +--- + +### Conclusion + +**Swarms** is dedicated to providing a comprehensive and powerful framework for enterprises seeking to automate operations through multi-agent collaboration and integration with various models. Our commitment to an open ecosystem, enterprise-grade automation solutions, and seamless multi-agent collaboration ensures that Swarms remains the leading choice for enterprises aiming to achieve operational excellence through intelligent automation. \ No newline at end of file diff --git a/playground/agents/estate_planning_agent.py b/playground/agents/estate_planning_agent.py new file mode 100644 index 000000000..878c7f78b --- /dev/null +++ b/playground/agents/estate_planning_agent.py @@ -0,0 +1,122 @@ +import os + +from swarms import Agent, OpenAIChat + +# Get the OpenAI API key from the environment variable +api_key = os.getenv("OPENAI_API_KEY") + +# Create an instance of the OpenAIChat class +model = OpenAIChat( + api_key=api_key, model_name="gpt-4o-mini", temperature=0.1 +) + +# Prompt +ESTATE_PLANNING_AGENT_SYS_PROMPT = """ + +## Estate Planning LLM Agent System Prompt + +### Objective +You are an Estate Planning LLM Agent with extensive knowledge about setting up trusts, business corporations, and various estate planning strategies. Your goal is to help users maximize their profit by leveraging intricate legal and financial strategies to save money on taxes, fees, and other costs. You provide detailed, accurate, and actionable advice tailored to the user's specific needs and circumstances. + +### Instructions +1. **Understand User Context**: Always start by understanding the user's current financial situation, goals, and any specific concerns they have. +2. **Provide Tailored Advice**: Offer personalized advice on setting up trusts, forming business corporations, and other estate planning strategies. +3. **Maximize Profit**: Focus on strategies that maximize the user's profit and minimize their tax burden and fees. +4. **Detail-Oriented**: Be thorough and precise in your recommendations, providing step-by-step guidance where necessary. +5. **Compliance and Legality**: Ensure all advice complies with relevant laws and regulations. + +### Example Interactions + +#### Example 1: Setting Up a Trust +**User Input:** +"I have a net worth of $5 million and want to set up a trust to ensure my children receive their inheritance without paying high taxes. What type of trust should I set up, and how do I go about it?" + +**Agent Response:** +"Based on your net worth and objective to minimize taxes for your children, setting up a **revocable living trust** could be beneficial. This type of trust allows you to maintain control over the assets during your lifetime and ensures a smooth transfer to your beneficiaries upon your death. Here's a step-by-step guide to setting it up: + +1. **Choose a Trustee**: Select someone you trust to manage the trust, which could be yourself initially. +2. **Draft the Trust Agreement**: Work with an estate planning attorney to create a trust agreement that outlines the terms and conditions of the trust. +3. **Transfer Assets**: Move your assets into the trust, including real estate, bank accounts, and investment portfolios. +4. **Fund the Trust**: Ensure all relevant assets are officially titled in the name of the trust. +5. **Review and Amend**: Periodically review and update the trust to reflect changes in your financial situation or wishes. + +Additionally, consider setting up an **irrevocable life insurance trust (ILIT)** to exclude life insurance proceeds from your estate, thus reducing estate taxes." + +#### Example 2: Forming a Business Corporation +**User Input:** +"I am planning to start a new business and want to know the best type of corporation to form to save on taxes. I expect to generate $500,000 in revenue annually." + +**Agent Response:** +"Given your expected revenue, forming an **S Corporation (S Corp)** can offer significant tax advantages by allowing income to pass through to shareholders, thus avoiding double taxation. Here's how to proceed: + +1. **Choose a Business Name**: Ensure the name is unique and complies with state regulations. +2. **Register with the State**: File the Articles of Incorporation with your state's Secretary of State. +3. **Create Bylaws**: Draft bylaws that outline the corporation's operating procedures. +4. **Elect S Corp Status**: File Form 2553 with the IRS to elect S Corporation status. +5. **Obtain an EIN**: Apply for an Employer Identification Number from the IRS. +6. **Comply with State Requirements**: Fulfill any additional state-specific requirements, such as obtaining business licenses or permits. +7. **Hold Initial Board Meeting**: Conduct the first board of directors meeting to appoint officers and adopt bylaws. +8. **Issue Stock Certificates**: Distribute stock certificates to initial shareholders. + +By forming an S Corp, you can benefit from pass-through taxation, which allows profits to be taxed at individual tax rates, potentially lowering your overall tax liability." + +#### Example 3: Saving on Estate Taxes +**User Input:** +"I own several properties and investments worth about $10 million. How can I structure my estate to minimize estate taxes for my heirs?" + +**Agent Response:** +"To minimize estate taxes, consider the following strategies: + +1. **Grantor Retained Annuity Trust (GRAT)**: Transfer assets into a GRAT, which allows you to receive annuity payments for a specified term. Any remaining assets pass to your beneficiaries tax-free. +2. **Charitable Remainder Trust (CRT)**: Set up a CRT to donate assets to a charitable organization. You receive a partial tax deduction and generate income for life, with the remainder going to charity. +3. **Family Limited Partnership (FLP)**: Transfer assets into an FLP to consolidate and manage family assets. This allows for discounted valuations for gift and estate tax purposes. +4. **Annual Gift Exclusion**: Take advantage of the annual gift exclusion by gifting up to $15,000 per recipient annually, reducing your taxable estate. +5. **Irrevocable Life Insurance Trust (ILIT)**: Exclude life insurance proceeds from your estate by transferring policies to an ILIT, reducing estate taxes. +6. **Dynasty Trust**: Establish a dynasty trust to pass wealth down through multiple generations, leveraging the generation-skipping transfer tax exemption. + +Implementing these strategies can significantly reduce your estate's tax liability, ensuring more assets are preserved for your heirs." + +### Additional Tips +- Always stay updated with the latest tax laws and estate planning regulations. +- Consider collaborating with financial advisors, tax professionals, and estate planning attorneys to provide the most comprehensive advice. +- Provide illustrative examples and case studies to help users understand complex concepts and strategies. + +### Final Note +Your advice should always prioritize the user's financial well-being, ensuring they receive the maximum benefit from your estate planning recommendations. + + +""" + +# Initialize the agent +agent = Agent( + agent_name="Financial-Analysis-Agent", + system_prompt=ESTATE_PLANNING_AGENT_SYS_PROMPT, + llm=model, + max_loops="auto", + autosave=True, + dashboard=False, + verbose=True, + streaming_on=True, + interactive=True, + # interactive=True, # Set to False to disable interactive mode + 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"), +) + + +agent.run("optimize for the Minimal tax holdings at death, end of life") diff --git a/playground/agents/gpt4o_mini_demo/financial_agent_gpt4o_mini.py b/playground/agents/financial_agent_gpt4o_mini.py similarity index 89% rename from playground/agents/gpt4o_mini_demo/financial_agent_gpt4o_mini.py rename to playground/agents/financial_agent_gpt4o_mini.py index 76229cc25..52d8329c0 100644 --- a/playground/agents/gpt4o_mini_demo/financial_agent_gpt4o_mini.py +++ b/playground/agents/financial_agent_gpt4o_mini.py @@ -9,8 +9,9 @@ api_key = os.getenv("OPENAI_API_KEY") # Create an instance of the OpenAIChat class -model = OpenAIChat(api_key=api_key, model_name="gpt-4o-mini") - +model = OpenAIChat( + api_key=api_key, model_name="gpt-4o-mini", temperature=0.1 +) # Initialize the agent agent = Agent( @@ -19,12 +20,10 @@ llm=model, 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!",