From f57adb6c4b6867e72ec81560349cf9beeba7bf0e Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Sat, 15 Jun 2024 13:39:26 -0700 Subject: [PATCH] [CLEANUP] [DOCS][CLEANUP] --- .env.example | 1 + README.md | 55 +- docs/mkdocs.yml | 14 +- docs/swarms/index_overview.md | 0 docs/swarms/structs/moa.md | 2 +- docs/swarms/structs/multi_process_workflow.md | 124 +++ .../swarms/structs/multi_threaded_workflow.md | 113 +++ example.py | 3 +- playground/agents/agent_ops.py | 13 +- .../agent_with_longterm_memory.py | 12 +- playground/agents/new_perplexity_agent.py | 40 + playground/memory/chromadb_example.py | 8 +- playground/memory/mongodb.py | 14 + playground/models/fire_works.py | 13 + .../agent/multion/multion_example.ipynb | 801 ++++++++++++++++++ .../mixture_of_agents/agent_ops_moa.py | 451 ++++++++++ .../mixture_of_agents/moa_with_scp.py | 441 ++++++++++ .../swarm_of_ba_agents/agents.py | 732 ++++++++++++++++ .../structs/search_arena/requirements.txt | 3 + .../structs/search_arena/search_agents.py | 339 ++++++++ scripts/cleanup/json_log_cleanup.py | 2 +- swarms/models/popular_llms.py | 1 + swarms/structs/agent.py | 185 +++- swarms/structs/base_swarm.py | 50 +- swarms/structs/hiearchical_swarm.py | 118 ++- swarms/structs/mixture_of_agents.py | 33 +- swarms/structs/scp.py | 2 +- swarms/tools/tool_dataset_generator.py | 73 ++ swarms/utils/streaming.py | 36 + 29 files changed, 3572 insertions(+), 107 deletions(-) delete mode 100644 docs/swarms/index_overview.md create mode 100644 docs/swarms/structs/multi_process_workflow.md create mode 100644 docs/swarms/structs/multi_threaded_workflow.md rename playground/{structs/agent => agents}/agent_with_longterm_memory.py (66%) create mode 100644 playground/agents/new_perplexity_agent.py create mode 100644 playground/memory/mongodb.py create mode 100644 playground/models/fire_works.py create mode 100644 playground/structs/agent/multion/multion_example.ipynb create mode 100644 playground/structs/multi_agent_collaboration/mixture_of_agents/agent_ops_moa.py create mode 100644 playground/structs/multi_agent_collaboration/mixture_of_agents/moa_with_scp.py create mode 100644 playground/structs/multi_agent_collaboration/swarm_of_ba_agents/agents.py create mode 100644 playground/structs/search_arena/requirements.txt create mode 100644 playground/structs/search_arena/search_agents.py create mode 100644 swarms/tools/tool_dataset_generator.py create mode 100644 swarms/utils/streaming.py diff --git a/.env.example b/.env.example index 7776faeb..77032cb5 100644 --- a/.env.example +++ b/.env.example @@ -18,3 +18,4 @@ HF_API_KEY="your_huggingface_api_key_here" USE_TELEMETRY=True AGENTOPS_API_KEY="" +FIREWORKS_API_KEY="" \ No newline at end of file diff --git a/README.md b/README.md index 1155b7cf..ee925366 100644 --- a/README.md +++ b/README.md @@ -111,37 +111,50 @@ agent.run("Generate a 10,000 word blog on health and wellness.") `Agent` equipped with quasi-infinite long term memory. Great for long document understanding, analysis, and retrieval. ```python +import os + +from dotenv import load_dotenv + +# Import the OpenAIChat model and the Agent struct from swarms import Agent, OpenAIChat -from playground.memory.chromadb_example import ChromaDB # Copy and paste the code and put it in your own local directory. +from playground.memory.chromadb_example import ChromaDB -# Making an instance of the ChromaDB class -memory = ChromaDB( +# Load the environment variables +load_dotenv() + +# Get the API key from the environment +api_key = os.environ.get("OPENAI_API_KEY") + + +# Initilaize the chromadb client +chromadb = ChromaDB( metric="cosine", - n_results=3, - output_dir="results", - docs_folder="docs", + output_dir="scp", + docs_folder="artifacts", ) -# Initializing the agent with the Gemini instance and other parameters +# Initialize the language model +llm = OpenAIChat( + temperature=0.5, + openai_api_key=api_key, + max_tokens=1000, +) + +## Initialize the workflow agent = Agent( - agent_name="Covid-19-Chat", - agent_description=( - "This agent provides information about COVID-19 symptoms." - ), - llm=OpenAIChat(), - max_loops="auto", + llm=llm, + name = "Health and Wellness Blog", + system_prompt="Generate a 10,000 word blog on health and wellness.", + max_loops=4, autosave=True, - verbose=True, - long_term_memory=memory, - stopping_condition="finish", + dashboard=True, + long_term_memory=chromadb, + memory_chunk_size=300, ) -# Defining the task and image path -task = ("What are the symptoms of COVID-19?",) +# Run the workflow on a task +agent.run("Generate a 10,000 word blog on health and wellness.") -# Running the agent with the specified task and image -out = agent.run(task) -print(out) ``` diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 401ec44b..46cd8acb 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -97,11 +97,15 @@ nav: - Framework: - Overview: "swarms/index.md" - Models: "swarms/models/index.md" + - How to Create A Custom Language Model: "swarms/models/custom_model.md" + - Deploying Azure OpenAI in Production, A Comprehensive Guide: "swarms/models/azure_openai.md" - Agents: - Overview: "swarms/structs/index.md" - Build Agents: "swarms/structs/diy_your_own_agent.md" - Agents with Memory: "swarms/memory/diy_memory.md" - Agents with tools: "swarms/tools/main.md" + - DIY Build Your Own Agent: "diy_your_own_agent.md" + - Equipping Autonomous Agents with Tools: "examples/tools_agent.md" - Multi-Agent Collaboration: - Overview: "swarms/structs/multi_agent_orchestration.md" - Workflows: "swarms/structs/workflows.md" @@ -159,16 +163,6 @@ nav: - Getting Started with SOTA Vision Language Models VLM: "swarms_cloud/getting_started.md" - Enterprise Guide to High-Performance Multi-Agent LLM Deployments: "swarms_cloud/production_deployment.md" - Under The Hood The Swarm Cloud Serving Infrastructure: "swarms_cloud/architecture.md" - - Guides: - - Models: - - How to Create A Custom Language Model: "swarms/models/custom_model.md" - - Deploying Azure OpenAI in Production, A Comprehensive Guide: "swarms/models/azure_openai.md" - - Agents: - - Agent: "examples/flow.md" - - DIY Build Your Own Agent: "diy_your_own_agent.md" - - Equipping Autonomous Agents with Tools: "examples/tools_agent.md" - - Swarms: - - SequentialWorkflow: "examples/reliable_autonomous_agents.md" - References: - Agent Glossary: "swarms/glossary.md" - List of The Best Multi-Agent Papers: "swarms/papers.md" \ No newline at end of file diff --git a/docs/swarms/index_overview.md b/docs/swarms/index_overview.md deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/swarms/structs/moa.md b/docs/swarms/structs/moa.md index 2fe489c7..6c0f5959 100644 --- a/docs/swarms/structs/moa.md +++ b/docs/swarms/structs/moa.md @@ -225,7 +225,7 @@ print(history) #### Example 2: Verbose Output and Auto-Save ```python -from swarms import MixtureOfAgents, Agent, OpenAIOpenAIChat +from swarms import MixtureOfAgents, Agent, OpenAIChat # Define Agents # Define agents diff --git a/docs/swarms/structs/multi_process_workflow.md b/docs/swarms/structs/multi_process_workflow.md new file mode 100644 index 00000000..d89134d6 --- /dev/null +++ b/docs/swarms/structs/multi_process_workflow.md @@ -0,0 +1,124 @@ +# MultiProcessWorkflow Documentation + + +The `MultiProcessWorkflow` class provides a framework for executing tasks concurrently using multiple processes. This class leverages Python's `multiprocessing` module to parallelize task execution, thereby enhancing performance and efficiency. It includes features such as automatic task retry on failure and optional autosaving of results. This documentation details the class, its parameters, attributes, methods, and usage examples. + +## Class Definition + +### `MultiProcessWorkflow` + + +## Parameters + +| Parameter | Type | Default | Description | +|---------------|---------------------|---------|---------------------------------------------------------------| +| `max_workers` | `int` | `5` | The maximum number of workers to use for parallel processing. | +| `autosave` | `bool` | `True` | Flag indicating whether to automatically save the workflow. | +| `agents` | `Sequence[Agent]` | `None` | A list of Agent objects representing the workflow agents. | +| `*args` | `tuple` | | Additional positional arguments. | +| `**kwargs` | `dict` | | Additional keyword arguments. | + +## Attributes + +| Attribute | Type | Description | +|-----------------|---------------------|--------------------------------------------------------------| +| `max_workers` | `int` | The maximum number of workers to use for parallel processing.| +| `autosave` | `bool` | Flag indicating whether to automatically save the workflow. | +| `agents` | `Sequence[Agent]` | A list of Agent objects representing the workflow agents. | + +## Methods + +### `execute_task` + +#### Description + +The `execute_task` method executes a given task and handles any exceptions that may occur during execution. If agents are defined, it will execute the task using each agent in sequence. + +#### Usage Example + +```python +# Define a task +task = Task() + +# Execute the task +workflow = MultiProcessWorkflow() +result = workflow.execute_task(task) +print(result) +``` + +### `run` + +#### Description + +The `run` method executes the workflow by running the given task using multiple processes. It manages the task execution using a process pool and collects the results. + +#### Usage Example + +```python +from swarms.structs.multi_process_workflow import MultiProcessingWorkflow +from swarms.structs.task import Task +from datetime import datetime +from time import sleep + +# Define a simple task +def simple_task(): + sleep(1) + return datetime.now() + +# Create a task object +task = Task( + name="Simple Task", + execute=simple_task, + priority=1, +) + +# Create a workflow with the task +workflow = MultiProcessWorkflow(max_workers=3, autosave=True, agents=[agent1, agent2]) + +# Run the workflow +results = workflow.run(task) + +# Print the results +print(results) +``` + +## Detailed Functionality and Usage + +### Initialization + +When an instance of `MultiProcessWorkflow` is created, it initializes the following: + +- **max_workers**: Sets the maximum number of processes that can run concurrently. +- **autosave**: Determines if the workflow results should be saved automatically. +- **agents**: Accepts a list of agents that will perform the tasks. + +### Running Tasks + +The `run` method performs the following steps: + +1. **Initialize Results and Manager**: Creates a list to store results and a `Manager` to manage shared state between processes. +2. **Initialize Process Pool**: Creates a pool of worker processes. +3. **Submit Tasks**: Iterates over the agents, submitting tasks to the pool for execution and collecting the results. +4. **Wait for Completion**: Waits for all tasks to complete and collects the results. +5. **Return Results**: Returns the list of results from all executed tasks. + +### Autosave Task Result + +Although the autosave functionality is mentioned in the parameters, it is not explicitly defined in the given code. The implementation for autosaving should be added based on the specific requirements of the application. + +## Additional Information and Tips + +- **Process Safety**: The use of `Manager` ensures that the list of results is managed safely across multiple processes. +- **Logging**: The class uses the `logger` module to log information about task execution, retries, and failures. +- **Error Handling**: The retry mechanism in the `execute_task` method helps in handling transient errors by attempting to re-execute failed tasks. + +## References and Resources + +For more information on multiprocessing in Python, refer to the following resources: + +- [Python Multiprocessing Documentation](https://docs.python.org/3/library/multiprocessing.html) +- [Python Logging Documentation](https://docs.python.org/3/library/logging.html) + +--- + +By following this detailed documentation, users can effectively understand and utilize the `MultiProcessWorkflow` class to execute tasks concurrently with multiple processes. The examples provided help in demonstrating the practical usage of the class. \ No newline at end of file diff --git a/docs/swarms/structs/multi_threaded_workflow.md b/docs/swarms/structs/multi_threaded_workflow.md new file mode 100644 index 00000000..3b4f91cb --- /dev/null +++ b/docs/swarms/structs/multi_threaded_workflow.md @@ -0,0 +1,113 @@ +# MultiThreadedWorkflow Documentation + +The `MultiThreadedWorkflow` class represents a multi-threaded workflow designed to execute tasks concurrently using a thread pool. This class is highly useful in scenarios where tasks need to be executed in parallel to improve performance and efficiency. The workflow ensures that tasks are managed in a priority-based queue, and it includes mechanisms for retrying failed tasks and optionally saving task results automatically. + +## Class Definition + +### `MultiThreadedWorkflow` + +## Parameters + +| Parameter | Type | Default | Description | +|---------------|-----------------------|---------|---------------------------------------------------------------| +| `max_workers` | `int` | `5` | The maximum number of worker threads in the thread pool. | +| `autosave` | `bool` | `True` | Flag indicating whether to automatically save task results. | +| `tasks` | `List[PriorityTask]` | `None` | List of priority tasks to be executed. | +| `retry_attempts` | `int` | `3` | The maximum number of retry attempts for failed tasks. | +| `*args` | `tuple` | | Variable length argument list. | +| `**kwargs` | `dict` | | Arbitrary keyword arguments. | + +## Attributes + +| Attribute | Type | Description | +|------------------|--------------------|----------------------------------------------------------------| +| `max_workers` | `int` | The maximum number of worker threads in the thread pool. | +| `autosave` | `bool` | Flag indicating whether to automatically save task results. | +| `retry_attempts` | `int` | The maximum number of retry attempts for failed tasks. | +| `tasks_queue` | `PriorityQueue` | The queue that holds the priority tasks. | +| `lock` | `Lock` | The lock used for thread synchronization. | + +## Methods + +### `run` + + +#### Description + +The `run` method executes the tasks stored in the priority queue using a thread pool. It handles task completion, retries failed tasks up to a specified number of attempts, and optionally saves the results of tasks if the autosave flag is set. + +#### Usage Example + +```python +from swarms import MultiThreadedWorkflow, PriorityTask, Task + +# Define some tasks +tasks = [PriorityTask(task=Task()), PriorityTask(task=Task())] + +# Create a MultiThreadedWorkflow instance +workflow = MultiThreadedWorkflow(max_workers=3, autosave=True, tasks=tasks, retry_attempts=2) + +# Run the workflow +results = workflow.run() +print(results) +``` + +### `_autosave_task_result` + +#### Description + +The `_autosave_task_result` method is responsible for saving the results of a task. It uses a thread lock to ensure that the autosave operation is thread-safe. + +#### Usage Example + +This method is intended for internal use and is typically called by the `run` method. However, here is an example of how it might be used directly: + +```python +# Create a task and result +task = Task() +result = task.execute() + +# Autosave the result +workflow = MultiThreadedWorkflow() +workflow._autosave_task_result(task, result) +``` + +## Detailed Functionality and Usage + +### Initialization + +When an instance of `MultiThreadedWorkflow` is created, it initializes the following: + +- **max_workers**: Sets the maximum number of threads that can run concurrently. +- **autosave**: Determines if the task results should be saved automatically. +- **tasks**: Accepts a list of tasks that need to be executed. If no tasks are provided, an empty list is used. +- **retry_attempts**: Sets the maximum number of retry attempts for failed tasks. +- **tasks_queue**: A priority queue to manage tasks based on their priority. +- **lock**: A threading lock to ensure thread-safe operations. + +### Running Tasks + +The `run` method performs the following steps: + +1. **Initialize Results and Executor**: Creates a list to store results and a `ThreadPoolExecutor` to manage the threads. +2. **Submit Tasks**: Iterates over the tasks in the queue, submitting them to the executor for execution and storing the future objects. +3. **Monitor Completion**: Uses the `wait` function to monitor the completion of tasks. Once a task is completed, it retrieves the result or catches exceptions. +4. **Retry Mechanism**: If a task fails, it checks the number of attempts made and retries the task if the limit is not reached. +5. **Autosave**: If the `autosave` flag is set, the `_autosave_task_result` method is called to save the task results. + +### Autosave Task Result + +The `_autosave_task_result` method handles the saving of task results. It uses a threading lock to ensure that the save operation is not interrupted by other threads. + +## Additional Information and Tips + +- **Thread Safety**: The use of threading locks ensures that the operations are thread-safe, preventing race conditions. +- **Logging**: The class uses the logging module to log information about task completion, retries, and failures. +- **Error Handling**: The retry mechanism helps in handling transient errors by attempting to re-execute failed tasks. + +## References and Resources + +For more information on threading and concurrent execution in Python, refer to the following resources: + +- [Python Threading Documentation](https://docs.python.org/3/library/threading.html) +- [Python Concurrent Futures Documentation](https://docs.python.org/3/library/concurrent.futures.html) diff --git a/example.py b/example.py index b6f8d712..a0e85d52 100644 --- a/example.py +++ b/example.py @@ -40,10 +40,11 @@ agent = Agent( dynamic_temperature_enabled=True, dashboard=False, verbose=True, + streaming_on=True, # interactive=True, # Set to False to disable interactive mode # stopping_token="", # saved_state_path="accounting_agent.json", - tools=[calculate_profit, generate_report], + # tools=[calculate_profit, generate_report], # docs_folder="docs", # pdf_path="docs/accounting_agent.pdf", ) diff --git a/playground/agents/agent_ops.py b/playground/agents/agent_ops.py index 5d9bf467..f2dd1489 100644 --- a/playground/agents/agent_ops.py +++ b/playground/agents/agent_ops.py @@ -1,12 +1,11 @@ from swarms import Agent, OpenAIChat - # Initialize the agent agent = Agent( - agent_name="Transcript Generator", - system_prompt="Generate a transcript for a youtube video on what swarms are!", + agent_name="Accounting Agent", + system_prompt="Generate a financial report for the company's quarterly earnings.", agent_description=( - "Generate a transcript for a youtube video on what swarms" " are!" + "Generate a financial report for the company's quarterly earnings." ), llm=OpenAIChat(), max_loops=1, @@ -17,9 +16,11 @@ agent = Agent( stopping_token="", interactive=False, state_save_file_type="json", - saved_state_path="transcript_generator.json", + saved_state_path="accounting_agent.json", agent_ops_on=True, ) # Run the Agent on a task -agent.run("Generate a transcript for a youtube video on what swarms are!") +agent.run( + "Generate a financial report for the company's quarterly earnings!" +) diff --git a/playground/structs/agent/agent_with_longterm_memory.py b/playground/agents/agent_with_longterm_memory.py similarity index 66% rename from playground/structs/agent/agent_with_longterm_memory.py rename to playground/agents/agent_with_longterm_memory.py index c4923e97..dc73b8c1 100644 --- a/playground/structs/agent/agent_with_longterm_memory.py +++ b/playground/agents/agent_with_longterm_memory.py @@ -3,7 +3,8 @@ import os from dotenv import load_dotenv # Import the OpenAIChat model and the Agent struct -from swarms import Agent, ChromaDB, OpenAIChat +from swarms import Agent, OpenAIChat +from playground.memory.chromadb_example import ChromaDB # Load the environment variables load_dotenv() @@ -15,13 +16,13 @@ api_key = os.environ.get("OPENAI_API_KEY") # Initilaize the chromadb client chromadb = ChromaDB( metric="cosine", - output="results", + output_dir="scp", + docs_folder="artifacts", ) # Initialize the language model llm = OpenAIChat( temperature=0.5, - model_name="gpt-4", openai_api_key=api_key, max_tokens=1000, ) @@ -29,10 +30,13 @@ llm = OpenAIChat( ## Initialize the workflow agent = Agent( llm=llm, + name="Health and Wellness Blog", + system_prompt="Generate a 10,000 word blog on health and wellness.", max_loops=4, autosave=True, dashboard=True, - long_term_memory=chromadb, + long_term_memory=[chromadb], + memory_chunk_size=300, ) # Run the workflow on a task diff --git a/playground/agents/new_perplexity_agent.py b/playground/agents/new_perplexity_agent.py new file mode 100644 index 00000000..5e2032bd --- /dev/null +++ b/playground/agents/new_perplexity_agent.py @@ -0,0 +1,40 @@ +from swarms import Agent +from swarms.models.llama3_hosted import llama3Hosted +from playground.memory.chromadb_example import ChromaDB +from swarms.tools.prebuilt.bing_api import fetch_web_articles_bing_api + +# Define the research system prompt +research_system_prompt = """ +Research Agent LLM Prompt: Summarizing Sources and Content +Objective: Your task is to summarize the provided sources and the content within those sources. The goal is to create concise, accurate, and informative summaries that capture the key points of the original content. +Instructions: +1. Identify Key Information: ... +2. Summarize Clearly and Concisely: ... +3. Preserve Original Meaning: ... +4. Include Relevant Details: ... +5. Structure: ... +""" + +# Initialize memory +memory = ChromaDB(output_dir="research_base", n_results=2) + +# Initialize the LLM +llm = llama3Hosted(temperature=0.2, max_tokens=3500) + +# Initialize the agent +agent = Agent( + agent_name="Research Agent", + system_prompt=research_system_prompt, + llm=llm, + max_loops="auto", + autosave=True, + dashboard=False, + interactive=True, + long_term_memory=memory, + tools=[fetch_web_articles_bing_api], +) + +# Define the task for the agent +task = "What is the impact of climate change on biodiversity?" +out = agent.run(task) +print(out) diff --git a/playground/memory/chromadb_example.py b/playground/memory/chromadb_example.py index 0f299b32..606c13f0 100644 --- a/playground/memory/chromadb_example.py +++ b/playground/memory/chromadb_example.py @@ -166,10 +166,10 @@ class ChromaDB(BaseVectorDatabase): for root, dirs, files in os.walk(self.docs_folder): for file in files: - file = os.path.join(self.docs_folder, file) - _, ext = os.path.splitext(file) - data = data_to_text(file) + file_path = os.path.join(root, file) # Change this line + _, ext = os.path.splitext(file_path) + data = data_to_text(file_path) added_to_db = self.add(str(data)) - print(f"{file} added to Database") + print(f"{file_path} added to Database") return added_to_db diff --git a/playground/memory/mongodb.py b/playground/memory/mongodb.py new file mode 100644 index 00000000..b37a5a2c --- /dev/null +++ b/playground/memory/mongodb.py @@ -0,0 +1,14 @@ +from pymongo.mongo_client import MongoClient +from pymongo.server_api import ServerApi + +uri = "mongodb+srv://kye:Kgx7d2FeLN7AyGNh@cluster0.ndu3b6d.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0" + +# Create a new client and connect to the server +client = MongoClient(uri, server_api=ServerApi("1")) + +# Send a ping to confirm a successful connection +try: + client.admin.command("ping") + print("Pinged your deployment. You successfully connected to MongoDB!") +except Exception as e: + print(e) diff --git a/playground/models/fire_works.py b/playground/models/fire_works.py new file mode 100644 index 00000000..114557c4 --- /dev/null +++ b/playground/models/fire_works.py @@ -0,0 +1,13 @@ +from swarms.models.popular_llms import Fireworks +import os + +# Initialize the model +llm = Fireworks( + temperature=0.2, + max_tokens=3500, + openai_api_key=os.getenv("FIREWORKS_API_KEY"), +) + +# Run the model +response = llm("What is the meaning of life?") +print(response) diff --git a/playground/structs/agent/multion/multion_example.ipynb b/playground/structs/agent/multion/multion_example.ipynb new file mode 100644 index 00000000..6131a64a --- /dev/null +++ b/playground/structs/agent/multion/multion_example.ipynb @@ -0,0 +1,801 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# pip3 install multion\n", + "# pip3 install swarms\n", + "import multion\n", + "from multion.client import MultiOn\n", + "from swarms import Agent\n", + "import os\n", + "from swarms.models.base_llm import BaseLLM\n", + "\n", + "def check_multion_api_key():\n", + " \"\"\"\n", + " Checks if the MultiOn API key is available in the environment variables.\n", + "\n", + " Returns:\n", + " str: The MultiOn API key.\n", + " \"\"\"\n", + " api_key = os.getenv(\"MULTION_API_KEY\")\n", + " return api_key\n", + "\n", + "\n", + "class MultiOnAgent(BaseLLM):\n", + " \"\"\"\n", + " Represents an agent that interacts with the MultiOn API to run tasks on a remote session.\n", + "\n", + " Args:\n", + " api_key (str): The API key for accessing the MultiOn API.\n", + " url (str): The URL of the remote session.\n", + " *args: Variable length argument list.\n", + " **kwargs: Arbitrary keyword arguments.\n", + "\n", + " Attributes:\n", + " client (MultiOn): The MultiOn client instance.\n", + " url (str): The URL of the remote session.\n", + " session_id (str): The ID of the current session.\n", + "\n", + " Methods:\n", + " run: Runs a task on the remote session.\n", + " \"\"\"\n", + "\n", + " def __init__(self, name: str = None, system_prompt: str = None, api_key: str = check_multion_api_key, url: str = \"https://huggingface.co/papers\", *args, **kwargs):\n", + " super().__init__(*args, **kwargs)\n", + " self.name = name\n", + " self.client = MultiOn(api_key=api_key)\n", + " self.url = url\n", + " self.system_prompt = system_prompt\n", + " self.session_id = None\n", + "\n", + " def run(self, task: str, *args, **kwargs):\n", + " \"\"\"\n", + " Runs a task on the remote session.\n", + "\n", + " Args:\n", + " task (str): The task to be executed on the remote session.\n", + " *args: Variable length argument list.\n", + " **kwargs: Arbitrary keyword arguments.\n", + " \"\"\"\n", + " # Create a new session\n", + " response = self.client.sessions.create(url=self.url, *args, **kwargs)\n", + " print(response.message)\n", + " self.session_id = response.session_id\n", + " \n", + " prompt = f\"{self.system_prompt} {task}\"\n", + " \n", + " # Keep stepping the session until the agent completes the task\n", + " while response.status == 'CONTINUE':\n", + " response = self.client.sessions.step(\n", + " session_id=self.session_id,\n", + " cmd=prompt,\n", + " include_screenshot=True,\n", + " *args,\n", + " **kwargs\n", + " )\n", + " \n", + " if response.status == 'DONE':\n", + " print('Task completed')\n", + " print(response.message)\n", + "\n", + " # Capture a screenshot of the session\n", + " get_screenshot = self.client.sessions.screenshot(session_id=self.session_id, *args, **kwargs)\n", + " print(\"Screenshot of session: \", get_screenshot.screenshot)\n", + "\n", + " # Close the session\n", + " close_session_response = self.client.sessions.close(session_id=self.session_id, *args, **kwargs)\n", + " print(\"Close session response: \", close_session_response)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "from swarms import MixtureOfAgents\n", + "\n", + "llm = MultiOnAgent(\n", + "\tname = \"MultiOnAgent\",\n", + ")\n", + "\n", + "\n", + "SEC_FILLING = \"\"\"\n", + "\n", + " \tThree Months Ended\n", + " \tApr 28, 2024\t\tApr 30, 2023\n", + "Revenue\t$\t26,044 \t\t\t$\t7,192 \t\n", + "Cost of revenue\t5,638 \t\t\t2,544 \t\n", + "Gross profit\t20,406 \t\t\t4,648 \t\n", + "Operating expenses\t \t\t \n", + "Research and development\t2,720 \t\t\t1,875 \t\n", + "Sales, general and administrative\t777 \t\t\t633 \t\n", + "Total operating expenses\t3,497 \t\t\t2,508 \t\n", + "Operating income\t16,909 \t\t\t2,140 \t\n", + "Interest income\t359 \t\t\t150 \t\n", + "Interest expense\t(64)\t\t\t(66)\t\n", + "Other, net\t75 \t\t\t(15)\t\n", + "Other income (expense), net\n", + "370 \t\t\t69 \t\n", + "Income before income tax\t17,279 \t\t\t2,209 \t\n", + "Income tax expense\t2,398 \t\t\t166 \t\n", + "Net income\t$\t14,881 \t\t\t$\t2,043 \t\n", + "Net income per share:\t\t\t\n", + "Basic\t$\t6.04 \t\t\t$\t0.83 \t\n", + "Diluted\t$\t5.98 \t\t\t$\t0.82 \t\n", + "Weighted average shares used in per share computation:\t\t\t\n", + "Basic\t2,462 \t\t\t2,470 \t\n", + "Diluted\t2,489 \t\t\t2,490 \t\n", + " \n", + "\n", + "See accompanying Notes to Condensed Consolidated Financial Statements.\n", + "3\n", + "\n", + "NVIDIA Corporation and Subsidiaries\n", + "Condensed Consolidated Statements of Comprehensive Income\n", + "(In millions)\n", + "(Unaudited)\n", + " \tThree Months Ended\n", + " \tApr 28, 2024\t\tApr 30, 2023\n", + " \t\t\t\n", + "Net income\t$\t14,881 \t\t\t$\t2,043 \t\n", + "Other comprehensive loss, net of tax\t\t\t\n", + "Available-for-sale securities:\t\t\t\n", + "Net change in unrealized gain (loss)\t(128)\t\t\t17 \t\n", + "Cash flow hedges:\t\t\t\n", + "Net change in unrealized loss\t(4)\t\t\t(13)\t\n", + "Reclassification adjustments for net realized loss included in net income\t(4)\t\t\t(11)\t\n", + "Net change in unrealized loss\t(8)\t\t\t(24)\t\n", + "Other comprehensive loss, net of tax\t(136)\t\t\t(7)\t\n", + "Total comprehensive income\t$\t14,745 \t\t\t$\t2,036 \t\n", + " \n", + "\n", + "See accompanying Notes to Condensed Consolidated Financial Statements.\n", + "\n", + "4\n", + "\n", + "NVIDIA Corporation and Subsidiaries\n", + "Condensed Consolidated Balance Sheets\n", + "(In millions)\n", + "(Unaudited)\n", + " \tApr 28, 2024\t\tJan 28, 2024\n", + "Assets\t\t\t\n", + "Current assets:\t \t\t \n", + "Cash and cash equivalents\t$\t7,587 \t\t\t$\t7,280 \t\n", + "Marketable securities\t23,851 \t\t\t18,704 \t\n", + "Accounts receivable, net\t12,365 \t\t\t9,999 \t\n", + "Inventories\t5,864 \t\t\t5,282 \t\n", + "Prepaid expenses and other current assets\t4,062 \t\t\t3,080 \t\n", + "Total current assets\t53,729 \t\t\t44,345 \t\n", + "Property and equipment, net\t4,006 \t\t\t3,914 \t\n", + "Operating lease assets\t1,532 \t\t\t1,346 \t\n", + "Goodwill\t4,453 \t\t\t4,430 \t\n", + "Intangible assets, net\t986 \t\t\t1,112 \t\n", + "Deferred income tax assets\t7,798 \t\t\t6,081 \t\n", + "Other assets\t4,568 \t\t\t4,500 \t\n", + "Total assets\t$\t77,072 \t\t\t$\t65,728 \t\n", + "Liabilities and Shareholders' Equity\t \t\t \n", + "Current liabilities:\t \t\t \n", + "Accounts payable\t$\t2,715 \t\t\t$\t2,699 \t\n", + "Accrued and other current liabilities\t11,258 \t\t\t6,682 \t\n", + "Short-term debt\t1,250 \t\t\t1,250 \t\n", + "Total current liabilities\t15,223 \t\t\t10,631 \t\n", + "Long-term debt\t8,460 \t\t\t8,459 \t\n", + "Long-term operating lease liabilities\t1,281 \t\t\t1,119 \t\n", + "Other long-term liabilities\t2,966 \t\t\t2,541 \t\n", + "Total liabilities\t27,930 \t\t\t22,750 \t\n", + "Commitments and contingencies - see Note 12\t\t\t\n", + "Shareholders’ equity:\t \t\t \n", + "Preferred stock\t— \t\t\t— \t\n", + "Common stock\t2 \t\t\t2 \t\n", + "Additional paid-in capital\t12,651 \t\t\t13,132 \t\n", + "Accumulated other comprehensive income (loss)\t(109)\t\t\t27 \t\n", + "Retained earnings\t36,598 \t\t\t29,817 \t\n", + "Total shareholders' equity\t49,142 \t\t\t42,978 \t\n", + "Total liabilities and shareholders' equity\t$\t77,072 \t\t\t$\t65,728 \t\n", + " \n", + "\n", + "See accompanying Notes to Condensed Consolidated Financial Statements.\n", + "\n", + "5\n", + "\n", + "NVIDIA Corporation and Subsidiaries\n", + "Condensed Consolidated Statements of Shareholders' Equity\n", + "For the Three Months Ended April 28, 2024 and April 30, 2023\n", + "(Unaudited) \n", + "Common Stock\n", + "Outstanding\t\tAdditional Paid-in Capital\t\tAccumulated Other Comprehensive Income (Loss)\t\tRetained Earnings\t\tTotal Shareholders' Equity\n", + "Shares\t\tAmount\t\t\t\t\n", + "(In millions, except per share data)\t\t\t\t\t\t\t\t\t\t\t\n", + "Balances, Jan 28, 2024\t2,464 \t\t\t$\t2 \t\t\t$\t13,132 \t\t\t$\t27 \t\t\t$\t29,817 \t\t\t$\t42,978 \t\n", + "Net income\t— \t\t\t— \t\t\t— \t\t\t— \t\t\t14,881 \t\t\t14,881 \t\n", + "Other comprehensive loss\t— \t\t\t— \t\t\t— \t\t\t(136)\t\t\t— \t\t\t(136)\t\n", + "Issuance of common stock from stock plans \t7 \t\t\t— \t\t\t285 \t\t\t— \t\t\t— \t\t\t285 \t\n", + "Tax withholding related to vesting of restricted stock units\t(2)\t\t\t— \t\t\t(1,752)\t\t\t— \t\t\t— \t\t\t(1,752)\t\n", + "Shares repurchased\t(10)\t\t\t— \t\t\t(33)\t\t\t— \t\t\t(8,002)\t\t\t(8,035)\t\n", + "Cash dividends declared and paid ($0.04 per common share)\n", + "— \t\t\t— \t\t\t— \t\t\t— \t\t\t(98)\t\t\t(98)\t\n", + "Stock-based compensation\t— \t\t\t— \t\t\t1,019 \t\t\t— \t\t\t— \t\t\t1,019 \t\n", + "Balances, Apr 28, 2024\t2,459 \t\t\t$\t2 \t\t\t$\t12,651 \t\t\t$\t(109)\t\t\t$\t36,598 \t\t\t$\t49,142 \t\n", + "Balances, Jan 29, 2023\t2,466 \t\t\t$\t2 \t\t\t$\t11,971 \t\t\t$\t(43)\t\t\t$\t10,171 \t\t\t$\t22,101 \t\n", + "Net income\t— \t\t\t— \t\t\t— \t\t\t— \t\t\t2,043 \t\t\t2,043 \t\n", + "Other comprehensive loss\t— \t\t\t— \t\t\t— \t\t\t(7)\t\t\t— \t\t\t(7)\t\n", + "Issuance of common stock from stock plans \t9 \t\t\t— \t\t\t246 \t\t\t— \t\t\t— \t\t\t246 \t\n", + "Tax withholding related to vesting of restricted stock units\t(2)\t\t\t— \t\t\t(507)\t\t\t— \t\t\t— \t\t\t(507)\t\n", + "Cash dividends declared and paid ($0.04 per common share)\n", + "— \t\t\t— \t\t\t— \t\t\t— \t\t\t(99)\t\t\t(99)\t\n", + "Stock-based compensation\t— \t\t\t— \t\t\t743 \t\t\t— \t\t\t— \t\t\t743 \t\n", + "Balances, Apr 30, 2023\t2,473 \t\t\t$\t2 \t\t\t$\t12,453 \t\t\t$\t(50)\t\t\t$\t12,115 \t\t\t$\t24,520 \t\n", + " \n", + "See accompanying Notes to Condensed Consolidated Financial Statements.\n", + "6\n", + "\n", + "NVIDIA Corporation and Subsidiaries\n", + "Condensed Consolidated Statements of Cash Flows\n", + "(In millions)\n", + "(Unaudited) \n", + " \tThree Months Ended\n", + " \tApr 28, 2024\t\tApr 30, 2023\n", + "Cash flows from operating activities:\t\t\t\n", + "Net income\t$\t14,881 \t\t\t$\t2,043 \t\n", + "Adjustments to reconcile net income to net cash provided by operating activities:\t\t\t\n", + "Stock-based compensation expense\t1,011 \t\t\t735 \t\n", + "Depreciation and amortization\t410 \t\t\t384 \t\n", + "Realized and unrealized (gains) losses on investments in non-affiliated entities, net\t(69)\t\t\t14 \t\n", + "Deferred income taxes\t(1,577)\t\t\t(1,135)\t\n", + "Other\t(145)\t\t\t(34)\t\n", + "Changes in operating assets and liabilities, net of acquisitions:\t\t\t\n", + "Accounts receivable\t(2,366)\t\t\t(252)\t\n", + "Inventories\t(577)\t\t\t566 \t\n", + "Prepaid expenses and other assets\t(726)\t\t\t(215)\t\n", + "Accounts payable\t(22)\t\t\t11 \t\n", + "Accrued and other current liabilities\t4,202 \t\t\t689 \t\n", + "Other long-term liabilities\t323 \t\t\t105 \t\n", + "Net cash provided by operating activities\t15,345 \t\t\t2,911 \t\n", + "Cash flows from investing activities:\t\t\t\n", + "Proceeds from maturities of marketable securities\t4,004 \t\t\t2,512 \t\n", + "Proceeds from sales of marketable securities\t149 \t\t\t— \t\n", + "Purchases of marketable securities\t(9,303)\t\t\t(2,801)\t\n", + "Purchases related to property and equipment and intangible assets\t(369)\t\t\t(248)\t\n", + "Acquisitions, net of cash acquired\t(39)\t\t\t(83)\t\n", + "Investments in non-affiliated entities\t(135)\t\t\t(221)\t\n", + "Net cash used in investing activities\t(5,693)\t\t\t(841)\t\n", + "Cash flows from financing activities:\t\t\t\n", + "Proceeds related to employee stock plans\t285 \t\t\t246 \t\n", + "Payments related to repurchases of common stock\t(7,740)\t\t\t— \t\n", + "Payments related to tax on restricted stock units\t(1,752)\t\t\t(507)\t\n", + "Dividends paid\t(98)\t\t\t(99)\t\n", + "Principal payments on property and equipment and intangible assets\t(40)\t\t\t(20)\t\n", + "Net cash used in financing activities\t(9,345)\t\t\t(380)\t\n", + "Change in cash and cash equivalents\t307 \t\t\t1,690 \t\n", + "Cash and cash equivalents at beginning of period\t7,280 \t\t\t3,389 \t\n", + "Cash and cash equivalents at end of period\t$\t7,587 \t\t\t$\t5,079 \t\n", + " \n", + "See accompanying Notes to Condensed Consolidated Financial Statements.\n", + "7\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements\n", + "(Unaudited)\n", + "\n", + "\n", + "Note 1 - Summary of Significant Accounting Policies\n", + "Basis of Presentation\n", + "The accompanying unaudited condensed consolidated financial statements were prepared in accordance with accounting principles generally accepted in the United States of America, or U.S. GAAP, for interim financial information and with the instructions to Form 10-Q and Article 10 of Securities and Exchange Commission, or SEC, Regulation S-X. The January 28, 2024 consolidated balance sheet was derived from our audited consolidated financial statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024, as filed with the SEC, but does not include all disclosures required by U.S. GAAP. In the opinion of management, all adjustments, consisting only of normal recurring adjustments considered necessary for a fair statement of results of operations and financial position, have been included. The results for the interim periods presented are not necessarily indicative of the results expected for any future period. The following information should be read in conjunction with the audited consolidated financial statements and notes thereto included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024. \n", + "Significant Accounting Policies\n", + "There have been no material changes to our significant accounting policies disclosed in Note 1 - Organization and Summary of Significant Accounting Policies, of the Notes to the Consolidated Financial Statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024.\n", + "Fiscal Year\n", + "We operate on a 52- or 53-week year, ending on the last Sunday in January. Fiscal years 2025 and 2024 are both 52-week years. The first quarters of fiscal years 2025 and 2024 were both 13-week quarters.\n", + "Principles of Consolidation\n", + "Our condensed consolidated financial statements include the accounts of NVIDIA Corporation and our wholly-owned subsidiaries. All intercompany balances and transactions have been eliminated in consolidation.\n", + "Use of Estimates\n", + "The preparation of financial statements in conformity with U.S. GAAP requires management to make estimates and assumptions that affect the reported amounts of assets and liabilities and disclosures of contingent assets and liabilities at the date of the financial statements and the reported amounts of revenue and expenses during the reporting period. Actual results could differ materially from our estimates. On an on-going basis, we evaluate our estimates, including those related to revenue recognition, cash equivalents and marketable securities, accounts receivable, inventories and product purchase commitments, income taxes, goodwill, stock-based compensation, litigation, investigation and settlement costs, property, plant, and equipment, and other contingencies. These estimates are based on historical facts and various other assumptions that we believe are reasonable.\n", + "Recently Issued Accounting Pronouncements\n", + "Recent Accounting Pronouncements Not Yet Adopted\n", + "In November 2023, the Financial Accounting Standards Board, or FASB, issued a new accounting standard to provide for additional disclosures about significant expenses in operating segments. The standard is effective for our annual reporting starting with fiscal year 2025 and for interim period reporting starting in fiscal year 2026 retrospectively. We are currently evaluating the impact of this standard on our Consolidated Financial Statements.\n", + "In December 2023, the FASB issued a new accounting standard which provides for new and updated income tax disclosures, including disaggregation of rate reconciliation and income taxes paid. The standard is effective for annual periods beginning after December 15, 2024. Early adoption is permitted and should be applied prospectively, with retrospective application permitted. We expect to adopt this standard in our annual reporting starting with fiscal year 2026. We are currently evaluating the impact of this standard on our Consolidated Financial Statements.\n", + "\n", + "\n", + "\n", + "8\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Note 2 - Leases\n", + "Our lease obligations primarily consist of operating leases for our headquarters complex, domestic and international office facilities, and data center space, with lease periods expiring between fiscal years 2025 and 2035.\n", + "Future minimum lease payments under our non-cancelable operating leases as of April 28, 2024 were as follows:\n", + "Operating Lease Obligations\n", + " \t(In millions)\n", + "Fiscal Year:\t \n", + "2025 (excluding first quarter of fiscal year 2025)\n", + "$\t221 \t\n", + "2026\t306 \t\n", + "2027\t290 \t\n", + "2028\t270 \t\n", + "2029\t236 \t\n", + "2030 and thereafter\n", + "410 \t\n", + "Total\t1,733 \t\n", + "Less imputed interest\t206 \t\n", + "Present value of net future minimum lease payments\t1,527 \t\n", + "Less short-term operating lease liabilities\t246 \t\n", + "Long-term operating lease liabilities\t$\t1,281 \t\n", + " \n", + "In addition, we have operating leases, primarily for our data centers, that are expected to commence during fiscal year 2025 with lease terms of 2 to 11 years for $923 million.\n", + "Operating lease expenses were $80 million and $59 million for the first quarter of fiscal years 2025 and 2024, respectively. Short-term and variable lease expenses for the first quarter of fiscal years 2025 and 2024 were not significant.\n", + "Other information related to leases was as follows:\n", + "Three Months Ended\n", + "Apr 28, 2024\t\tApr 30, 2023\n", + " \t(In millions)\n", + "Supplemental cash flows information\t\t\t \n", + "Operating cash flows used for operating leases\t$\t69 \t\t\t$\t61 \t\n", + "Operating lease assets obtained in exchange for lease obligations\t250 \t\t\t106 \t\n", + " \n", + "As of April 28, 2024, our operating leases had a weighted average remaining lease term of 6.3 years and a weighted average discount rate of 3.89%. As of January 28, 2024, our operating leases had a weighted average remaining lease term of 6.1 years and a weighted average discount rate of 3.76%.\n", + "9\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Note 3 - Stock-Based Compensation\n", + "Our stock-based compensation expense is associated with restricted stock units, or RSUs, performance stock units that are based on our corporate financial performance targets, or PSUs, performance stock units that are based on market conditions, or market-based PSUs, and our employee stock purchase plan, or ESPP.\n", + "Our Condensed Consolidated Statements of Income include stock-based compensation expense, net of amounts capitalized into inventory and subsequently recognized to cost of revenue, as follows:\n", + " \tThree Months Ended\n", + " \tApr 28, 2024\t\tApr 30, 2023\n", + "(In millions)\n", + "Cost of revenue\t$\t36 \t\t\t$\t27 \t\n", + "Research and development\t727 \t\t\t524 \t\n", + "Sales, general and administrative\t248 \t\t\t184 \t\n", + "Total\t$\t1,011 \t\t\t$\t735 \t\n", + " \n", + "Equity Award Activity\n", + "The following is a summary of our equity award transactions under our equity incentive plans:\n", + "RSUs, PSUs, and Market-based PSUs Outstanding\n", + " \tNumber of Shares\t\tWeighted Average Grant-Date Fair Value Per Share\n", + "(In millions, except per share data)\n", + "Balances, Jan 28, 2024\t37 \t\t\t$\t245.94 \t\n", + "Granted\t7 \t\t\t$\t801.79 \t\n", + "Vested\t(6)\t\t\t$\t176.59 \t\n", + "Balances, Apr 28, 2024\t38 \t\t\t$\t361.45 \t\n", + " \n", + "As of April 28, 2024, there was $13.2 billion of aggregate unearned stock-based compensation expense. This amount is expected to be recognized over a weighted average period of 2.6 years for RSUs, PSUs, and market-based PSUs, and 0.8 years for ESPP.\n", + "Note 4 - Net Income Per Share\n", + "The following is a reconciliation of the denominator of the basic and diluted net income per share computations for the periods presented:\n", + " \tThree Months Ended\n", + "Apr 28, 2024\t\tApr 30, 2023\n", + " \t(In millions, except per share data)\n", + "Numerator:\t \t\t \n", + "Net income\t$\t14,881 \t\t\t$\t2,043 \t\n", + "Denominator:\t\t\t\n", + "Basic weighted average shares\t2,462 \t\t\t2,470 \t\n", + "Dilutive impact of outstanding equity awards\t27 \t\t\t20 \t\n", + "Diluted weighted average shares\t2,489 \t\t\t2,490 \t\n", + "Net income per share:\t\t\t\n", + "Basic (1)\t$\t6.04 \t\t\t$\t0.83 \t\n", + "Diluted (2)\t$\t5.98 \t\t\t$\t0.82 \t\n", + "Equity awards excluded from diluted net income per share because their effect would have been anti-dilutive\t6 \t\t\t4 \t\n", + " \n", + "(1) Calculated as net income divided by basic weighted average shares.\n", + "(2) Calculated as net income divided by diluted weighted average shares.\n", + "10\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Diluted net income per share is computed using the weighted average number of common and potentially dilutive shares outstanding during the period, using the treasury stock method. Any anti-dilutive effect of equity awards outstanding is not included in the computation of diluted net income per share.\n", + "Note 5 - Income Taxes\n", + "Income tax expense was $2.4 billion and $166 million for the first quarter of fiscal years 2025 and 2024, respectively. Income tax expense as a percentage of income before income tax was 13.9% and 7.5% for the first quarter of fiscal years 2025 and 2024, respectively.\n", + "\n", + "The effective tax rate increased primarily due to a decreased effect of tax benefits from the foreign-derived intangible income deduction and stock-based compensation relative to the increase in income before income tax.\n", + "\n", + "Our effective tax rates for the first quarter of fiscal years 2025 and 2024 were lower than the U.S. federal statutory rate of 21% due to tax benefits from stock-based compensation, the foreign-derived intangible income deduction, income earned in jurisdictions that are subject to taxes lower than the U.S. federal statutory tax rate, and the U.S. federal research tax credit.\n", + "\n", + "While we believe that we have adequately provided for all uncertain tax positions, or tax positions where we believe it is not more-likely-than-not that the position will be sustained upon review, amounts asserted by tax authorities could be greater or less than our accrued position. Accordingly, our provisions on federal, state and foreign tax related matters to be recorded in the future may change as revised estimates are made or the underlying matters are settled or otherwise resolved with the respective tax authorities. As of April 28, 2024, we do not believe that our estimates, as otherwise provided for, on such tax positions will significantly increase or decrease within the next 12 months.\n", + "Note 6 - Cash Equivalents and Marketable Securities \n", + "Our cash equivalents and marketable securities related to publicly held debt securities are classified as “available-for-sale” debt securities.\n", + "The following is a summary of cash equivalents and marketable securities:\n", + " \tApr 28, 2024\n", + "Amortized\n", + "Cost\t\tUnrealized\n", + "Gain\t\tUnrealized\n", + "Loss\t\tEstimated\n", + "Fair Value\t\tReported as\n", + " \t\t\t\t\tCash Equivalents\t\tMarketable Securities\n", + " \t(In millions)\n", + "Corporate debt securities\t$\t11,397 \t\t\t$\t3 \t\t\t$\t(43)\t\t\t$\t11,357 \t\t\t$\t733 \t\t\t$\t10,624 \t\n", + "Debt securities issued by the U.S. Treasury\t11,314 \t\t\t— \t\t\t(62)\t\t\t11,252 \t\t\t886 \t\t\t10,366 \t\n", + "Money market funds\t5,374 \t\t\t— \t\t\t— \t\t\t5,374 \t\t\t5,374 \t\t\t— \t\n", + "Debt securities issued by U.S. government agencies\t2,826 \t\t\t— \t\t\t(7)\t\t\t2,819 \t\t\t189 \t\t\t2,630 \t\n", + "Certificates of deposit\t286 \t\t\t— \t\t\t— \t\t\t286 \t\t\t69 \t\t\t217 \t\n", + "Foreign government bonds\t14 \t\t\t— \t\t\t— \t\t\t14 \t\t\t— \t\t\t14 \t\n", + "Total\t$\t31,211 \t\t\t$\t3 \t\t\t$\t(112)\t\t\t$\t31,102 \t\t\t$\t7,251 \t\t\t$\t23,851 \t\n", + " \n", + "11\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + " \tJan 28, 2024\n", + "Amortized\n", + "Cost\t\tUnrealized\n", + "Gain\t\tUnrealized\n", + "Loss\t\tEstimated\n", + "Fair Value\t\tReported as\n", + " \t\t\t\t\tCash Equivalents\t\tMarketable Securities\n", + " \t(In millions)\n", + "Corporate debt securities\t$\t10,126 \t\t\t$\t31 \t\t\t$\t(5)\t\t\t$\t10,152 \t\t\t$\t2,231 \t\t\t$\t7,921 \t\n", + "Debt securities issued by the U.S. Treasury\t9,517 \t\t\t17 \t\t\t(10)\t\t\t9,524 \t\t\t1,315 \t\t\t8,209 \t\n", + "Money market funds\t3,031 \t\t\t— \t\t\t— \t\t\t3,031 \t\t\t3,031 \t\t\t— \t\n", + "Debt securities issued by U.S. government agencies\t2,326 \t\t\t8 \t\t\t(1)\t\t\t2,333 \t\t\t89 \t\t\t2,244 \t\n", + "Certificates of deposit\t510 \t\t\t— \t\t\t— \t\t\t510 \t\t\t294 \t\t\t216 \t\n", + "Foreign government bonds\t174 \t\t\t— \t\t\t— \t\t\t174 \t\t\t60 \t\t\t114 \t\n", + "Total\t$\t25,684 \t\t\t$\t56 \t\t\t$\t(16)\t\t\t$\t25,724 \t\t\t$\t7,020 \t\t\t$\t18,704 \t\n", + " \n", + "The following tables provide the breakdown of unrealized losses, aggregated by investment category and length of time that individual securities have been in a continuous loss position:\n", + "Apr 28, 2024\n", + " \tLess than 12 Months\t\t12 Months or Greater\t\tTotal\n", + " \tEstimated Fair Value\t\tGross Unrealized Loss\t\tEstimated Fair Value\t\tGross Unrealized Loss\t\tEstimated Fair Value\t\tGross Unrealized Loss\n", + " \t(In millions)\n", + "Debt securities issued by the U.S. Treasury\t$\t9,720 \t\t\t$\t(60)\t\t\t$\t756 \t\t\t$\t(2)\t\t\t$\t10,476 \t\t\t$\t(62)\t\n", + "Corporate debt securities\t6,943 \t\t\t(42)\t\t\t188 \t\t\t(1)\t\t\t7,131 \t\t\t(43)\t\n", + "Debt securities issued by U.S. government agencies\t2,391 \t\t\t(7)\t\t\t— \t\t\t— \t\t\t2,391 \t\t\t(7)\t\n", + "Total\t$\t19,054 \t\t\t$\t(109)\t\t\t$\t944 \t\t\t$\t(3)\t\t\t$\t19,998 \t\t\t$\t(112)\t\n", + " \n", + "Jan 28, 2024\n", + " \tLess than 12 Months\t\t12 Months or Greater\t\tTotal\n", + " \tEstimated Fair Value\t\tGross Unrealized Loss\t\tEstimated Fair Value\t\tGross Unrealized Loss\t\tEstimated Fair Value\t\tGross Unrealized Loss\n", + " \t(In millions)\n", + "Debt securities issued by the U.S. Treasury\t$\t3,343 \t\t\t$\t(5)\t\t\t$\t1,078 \t\t\t$\t(5)\t\t\t$\t4,421 \t\t\t$\t(10)\t\n", + "Corporate debt securities\t1,306 \t\t\t(3)\t\t\t618 \t\t\t(2)\t\t\t1,924 \t\t\t(5)\t\n", + "Debt securities issued by U.S. government agencies\t670 \t\t\t(1)\t\t\t— \t\t\t— \t\t\t670 \t\t\t(1)\t\n", + "Total\t$\t5,319 \t\t\t$\t(9)\t\t\t$\t1,696 \t\t\t$\t(7)\t\t\t$\t7,015 \t\t\t$\t(16)\t\n", + " \n", + "The gross unrealized losses are related to fixed income securities, driven primarily by changes in interest rates. Net realized gains and losses were not significant for all periods presented.\n", + "12\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "The amortized cost and estimated fair value of cash equivalents and marketable securities are shown below by contractual maturity.\n", + "Apr 28, 2024\t\tJan 28, 2024\n", + "Amortized Cost\t\tEstimated Fair Value\t\tAmortized Cost\t\tEstimated Fair Value\n", + "(In millions)\n", + "Less than one year\t$\t16,811 \t\t\t$\t16,800 \t\t\t$\t16,336 \t\t\t$\t16,329 \t\n", + "Due in 1 - 5 years\t14,400 \t\t\t14,302 \t\t\t9,348 \t\t\t9,395 \t\n", + "Total\t$\t31,211 \t\t\t$\t31,102 \t\t\t$\t25,684 \t\t\t$\t25,724 \t\n", + " \n", + "Note 7 - Fair Value of Financial Assets and Liabilities and Investments in Non-Affiliated Entities\n", + "The fair values of our financial assets and liabilities are determined using quoted market prices of identical assets or quoted market prices of similar assets from active markets. We review fair value hierarchy classification on a quarterly basis.\n", + "Pricing Category\t\tFair Value at\n", + "Apr 28, 2024\t\tJan 28, 2024\n", + "(In millions)\n", + "Assets\t\t\t\t\t\n", + "Cash equivalents and marketable securities:\t\t\t\t\t\n", + "Money market funds\tLevel 1\t\t$\t5,374 \t\t\t$\t3,031 \t\n", + "Corporate debt securities\tLevel 2\t\t$\t11,357 \t\t\t$\t10,152 \t\n", + "Debt securities issued by the U.S. Treasury\tLevel 2\t\t$\t11,252 \t\t\t$\t9,524 \t\n", + "Debt securities issued by U.S. government agencies\tLevel 2\t\t$\t2,819 \t\t\t$\t2,333 \t\n", + "Certificates of deposit\tLevel 2\t\t$\t286 \t\t\t$\t510 \t\n", + "Foreign government bonds\tLevel 2\t\t$\t14 \t\t\t$\t174 \t\n", + "Other assets (Investments in non-affiliated entities):\t\t\t\t\t\n", + "Publicly-held equity securities\tLevel 1\t\t$\t287 \t\t\t$\t225 \t\n", + "Liabilities (1)\t\t\t\t\t\n", + "0.584% Notes Due 2024\n", + "Level 2\t\t$\t1,242 \t\t\t$\t1,228 \t\n", + "3.20% Notes Due 2026\n", + "Level 2\t\t$\t960 \t\t\t$\t970 \t\n", + "1.55% Notes Due 2028\n", + "Level 2\t\t$\t1,096 \t\t\t$\t1,115 \t\n", + "2.85% Notes Due 2030\n", + "Level 2\t\t$\t1,331 \t\t\t$\t1,367 \t\n", + "2.00% Notes Due 2031\n", + "Level 2\t\t$\t1,026 \t\t\t$\t1,057 \t\n", + "3.50% Notes Due 2040\n", + "Level 2\t\t$\t805 \t\t\t$\t851 \t\n", + "3.50% Notes Due 2050\n", + "Level 2\t\t$\t1,487 \t\t\t$\t1,604 \t\n", + "3.70% Notes Due 2060\n", + "Level 2\t\t$\t368 \t\t\t$\t403 \t\n", + " \n", + "\n", + "(1) These liabilities are carried on our Condensed Consolidated Balance Sheets at their original issuance value, net of unamortized debt discount and issuance costs.\n", + "Investments in Non-Affiliated Entities\n", + "Our investments in non-affiliated entities include marketable equity securities, which are publicly traded, and non-marketable equity securities, which are primarily investments in privately held companies.\n", + "Our marketable equity securities have readily determinable fair values and are recorded in long-term other assets on our Condensed Consolidated Balance Sheets at fair value with changes in fair value recorded in Other income and expense, net on our Condensed Consolidated Statements of Income. Marketable equity securities totaled $287 million and $225 million as of April 28, 2024 and January 28, 2024, respectively. The net unrealized and realized gains and losses of investments in marketable securities were not significant for the first quarter of fiscal years 2025 and 2024.\n", + "13\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Our non-marketable equity securities are recorded in long-term other assets on our Condensed Consolidated Balance Sheets and valued under the measurement alternative. The carrying value of our non-marketable equity securities totaled $1.5 billion and $1.3 billion as of April 28, 2024 and January 28, 2024, respectively. Gains and losses on these investments, realized and unrealized, are recognized in Other income and expense, net on our Condensed Consolidated Statements of Income.\n", + " \n", + "(1) During the first quarter of fiscal years 2025 and 2024, we recorded an inventory provision of $210 million and $105 million, respectively, in cost of revenue.\n", + "\n", + " \tApr 28, 2024\t\tJan 28, 2024\n", + "Other Assets:\t(In millions)\n", + "Prepaid supply and capacity agreements (1)\t$\t2,232 \t\t\t$\t2,458 \t\n", + "Investments in non-affiliated entities\t1,750 \t\t\t1,546 \t\n", + "Prepaid royalties\t358 \t\t\t364 \t\n", + "Other\t228 \t\t\t132 \t\n", + "\n", + "We recognized $188 million in revenue in the first quarter of fiscal year 2025 from deferred revenue as of January 28, 2024.\n", + "Revenue allocated to remaining performance obligations, which includes deferred revenue and amounts that will be invoiced and recognized as revenue in future periods, was $1.3 billion as of April 28, 2024. We expect to recognize approximately 38% of this revenue over the next twelve months and the remainder thereafter. This excludes revenue related to performance obligations for contracts with a length of one year or less.\n", + "16\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Note 10 - Derivative Financial Instruments\n", + "We enter into foreign currency forward contracts to mitigate the impact of foreign currency exchange rate movements on our operating expenses. These contracts are designated as cash flow hedges for hedge accounting treatment. Gains or losses on the contracts are recorded in accumulated other comprehensive income or loss and reclassified to operating expense when the related operating expenses are recognized in earnings or ineffectiveness should occur.\n", + "We also enter into foreign currency forward contracts to mitigate the impact of foreign currency movements on monetary assets and liabilities. The change in fair value of these non-designated contracts is recorded in other income or expense and offsets the change in fair value of the hedged foreign currency denominated monetary assets and liabilities, which is also recorded in other income or expense.\n", + "The table below presents the notional value of our foreign currency contracts outstanding:\n", + " \tApr 28, 2024\t\tJan 28, 2024\n", + "(In millions)\n", + "Designated as cash flow hedges\t$\t1,198 \t\t\t$\t1,168 \t\n", + "Non-designated hedges\t$\t704 \t\t\t$\t597 \t\n", + " \n", + "The unrealized gains and losses or fair value of our foreign currency contracts was not significant as of April 28, 2024 and January 28, 2024.\n", + "As of April 28, 2024, all designated foreign currency contracts mature within 18 months. The expected realized gains and losses deferred to accumulated other comprehensive income or loss related to foreign currency contracts was not significant.\n", + "During the first quarter of fiscal years 2025 and 2024, the impact of derivative financial instruments designated for hedge accounting treatment in other comprehensive income or loss was not significant and the instruments were determined to be highly effective.\n", + "Note 11 - Debt\n", + "Long-Term Debt\n", + "Expected\n", + "Remaining Term (years)\t\tEffective\n", + "Interest Rate\t\tCarrying Value at\n", + "Apr 28, 2024\t\tJan 28, 2024\n", + "(In millions)\n", + "0.584% Notes Due 2024\n", + "0.1\t\t0.66%\t\t1,250 \t\t\t1,250 \t\n", + "3.20% Notes Due 2026\n", + "2.4\t\t3.31%\t\t1,000 \t\t\t1,000 \t\n", + "1.55% Notes Due 2028\n", + "4.1\t\t1.64%\t\t1,250 \t\t\t1,250 \t\n", + "2.85% Notes Due 2030\n", + "5.9\t\t2.93%\t\t1,500 \t\t\t1,500 \t\n", + "2.00% Notes Due 2031\n", + "7.1\t\t2.09%\t\t1,250 \t\t\t1,250 \t\n", + "3.50% Notes Due 2040\n", + "15.9\t\t3.54%\t\t1,000 \t\t\t1,000 \t\n", + "3.50% Notes Due 2050\n", + "25.9\t\t3.54%\t\t2,000 \t\t\t2,000 \t\n", + "3.70% Notes Due 2060\n", + "36.0\t\t3.73%\t\t500 \t\t\t500 \t\n", + "Unamortized debt discount and issuance costs\t\t\t\t\t\t(40)\t\t\t(41)\t\n", + "Net carrying amount\t\t\t\t\t\t9,710 \t\t\t9,709 \t\n", + "Less short-term portion\t\t\t\t\t\t(1,250)\t\t\t(1,250)\t\n", + "Total long-term portion\t\t\t\t\t\t$\t8,460 \t\t\t$\t8,459 \t\n", + " \n", + "Our notes are unsecured senior obligations. Existing and future liabilities of our subsidiaries will be effectively senior to the notes. Our notes pay interest semi-annually. We may redeem each of our notes prior to maturity, as defined in the applicable form of note. The maturity of the notes are calendar year.\n", + "As of April 28, 2024, we were in compliance with the required covenants, which are non-financial in nature, under the outstanding notes.\n", + "17\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Commercial Paper\n", + "We have a $575 million commercial paper program to support general corporate purposes. As of April 28, 2024, we had no commercial paper outstanding.\n", + "Note 12 - Commitments and Contingencies\n", + "Purchase Obligations\n", + "Our purchase obligations reflect our commitment to purchase components used to manufacture our products, including long-term supply and capacity agreements, certain software and technology licenses, other goods and services and long-lived assets.\n", + "As of April 28, 2024, we had outstanding inventory purchases and long-term supply and capacity obligations totaling $18.8 billion. We enter into agreements with contract manufacturers that allow them to procure inventory based upon our defined criteria, and in certain instances, these agreements are cancellable, able to be rescheduled, and adjustable for our business needs prior to placing firm orders. These changes may result in costs incurred through the date of cancellation. Other non-inventory purchase obligations were $10.6 billion, including $8.8 billion of multi-year cloud service agreements. We expect our cloud service agreements to be used to support our research and development efforts and our DGX Cloud offerings.\n", + "Total future purchase commitments as of April 28, 2024 are as follows:\n", + "Commitments\n", + " \t(In millions)\n", + "Fiscal Year:\t \n", + "2025 (excluding first quarter of fiscal year 2025)\n", + "$\t19,306 \t\n", + "2026\t3,438 \t\n", + "2027\t2,573 \t\n", + "2028\t2,222 \t\n", + "2029\t1,585 \t\n", + "2030 and thereafter\n", + "249 \t\n", + "Total\t$\t29,373 \t\n", + " \n", + "In addition to the purchase commitments included in the table above, at the end of the first quarter of fiscal year 2025, we had commitments of approximately $1.2 billion to complete business combinations, subject to closing conditions, and acquire land and buildings.\n", + "Accrual for Product Warranty Liabilities\n", + "The estimated amount of product warranty liabilities was $532 million and $306 million as of April 28, 2024 and January 28, 2024, respectively. The estimated product returns and product warranty activity consisted of the following:\n", + "Three Months Ended\n", + "Apr 28, 2024\t\tApr 30, 2023\n", + "(In millions)\n", + "Balance at beginning of period\t$\t306 \t\t\t$\t82 \t\n", + "Additions\t234 \t\t\t13 \t\n", + "Utilization\t(8)\t\t\t(18)\t\n", + "Balance at end of period\t$\t532 \t\t\t$\t77 \t\n", + " \n", + "We have provided indemnities for matters such as tax, product, and employee liabilities. We have included intellectual property indemnification provisions in our technology-related agreements with third parties. Maximum potential future payments cannot be estimated because many of these agreements do not have a maximum stated liability. We have not recorded any liability in our Condensed Consolidated Financial Statements for such indemnifications.\n", + "18\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Litigation\n", + "Securities Class Action and Derivative Lawsuits\n", + "The plaintiffs in the putative securities class action lawsuit, captioned 4:18-cv-07669-HSG, initially filed on December 21, 2018 in the United States District Court for the Northern District of California, and titled In Re NVIDIA Corporation Securities Litigation, filed an amended complaint on May 13, 2020. The amended complaint asserted that NVIDIA and certain NVIDIA executives violated Section 10(b) of the Securities Exchange Act of 1934, as amended, or the Exchange Act, and SEC Rule 10b-5, by making materially false or misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand between May 10, 2017 and November 14, 2018. Plaintiffs also alleged that the NVIDIA executives who they named as defendants violated Section 20(a) of the Exchange Act. Plaintiffs sought class certification, an award of unspecified compensatory damages, an award of reasonable costs and expenses, including attorneys’ fees and expert fees, and further relief as the Court may deem just and proper. On March 2, 2021, the district court granted NVIDIA’s motion to dismiss the complaint without leave to amend, entered judgment in favor of NVIDIA and closed the case. On March 30, 2021, plaintiffs filed an appeal from judgment in the United States Court of Appeals for the Ninth Circuit, case number 21-15604. On August 25, 2023, a majority of a three-judge Ninth Circuit panel affirmed in part and reversed in part the district court’s dismissal of the case, with a third judge dissenting on the basis that the district court did not err in dismissing the case. On November 15, 2023, the Ninth Circuit denied NVIDIA’s petition for rehearing en banc of the Ninth Circuit panel’s majority decision to reverse in part the dismissal of the case, which NVIDIA had filed on October 10, 2023. On November 21, 2023, NVIDIA filed a motion with the Ninth Circuit for a stay of the mandate pending NVIDIA’s petition for a writ of certiorari in the Supreme Court of the United States and the Supreme Court’s resolution of the matter. On December 5, 2023, the Ninth Circuit granted NVIDIA’s motion to stay the mandate. NVIDIA filed a petition for a writ of certiorari on March 4, 2024. Four amicus briefs in support of NVIDIA’s petition were filed on April 5, 2024.\n", + "The putative derivative lawsuit pending in the United States District Court for the Northern District of California, captioned 4:19-cv-00341-HSG, initially filed January 18, 2019 and titled In re NVIDIA Corporation Consolidated Derivative Litigation, was stayed pending resolution of the plaintiffs’ appeal in the In Re NVIDIA Corporation Securities Litigation action. On February 22, 2022, the court administratively closed the case, but stated that it would reopen the case once the appeal in the In Re NVIDIA Corporation Securities Litigation action is resolved. The stay remains in place. The lawsuit asserts claims, purportedly on behalf of us, against certain officers and directors of the Company for breach of fiduciary duty, unjust enrichment, waste of corporate assets, and violations of Sections 14(a), 10(b), and 20(a) of the Exchange Act based on the dissemination of allegedly false and misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand. The plaintiffs are seeking unspecified damages and other relief, including reforms and improvements to NVIDIA’s corporate governance and internal procedures.\n", + "The putative derivative actions initially filed September 24, 2019 and pending in the United States District Court for the District of Delaware, Lipchitz v. Huang, et al. (Case No. 1:19-cv-01795-UNA) and Nelson v. Huang, et. al. (Case No. 1:19-cv-01798- UNA), remain stayed pending resolution of the plaintiffs’ appeal in the In Re NVIDIA Corporation Securities Litigation action. The lawsuits assert claims, purportedly on behalf of us, against certain officers and directors of the Company for breach of fiduciary duty, unjust enrichment, insider trading, misappropriation of information, corporate waste and violations of Sections 14(a), 10(b), and 20(a) of the Exchange Act based on the dissemination of allegedly false, and misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand. The plaintiffs seek unspecified damages and other relief, including disgorgement of profits from the sale of NVIDIA stock and unspecified corporate governance measures.\n", + "Another putative derivative action was filed on October 30, 2023 in the Court of Chancery of the State of Delaware, captioned Horanic v. Huang, et al. (Case No. 2023-1096-KSJM). This lawsuit asserts claims, purportedly on behalf of us, against certain officers and directors of the Company for breach of fiduciary duty and insider trading based on the dissemination of allegedly false and misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand. The plaintiffs seek unspecified damages and other relief, including disgorgement of profits from the sale of NVIDIA stock and reform of unspecified corporate governance measures. This derivative matter is stayed pending the final resolution of In Re NVIDIA Corporation Securities Litigation action.\n", + "Accounting for Loss Contingencies\n", + "As of April 28, 2024, there are no accrued contingent liabilities associated with the legal proceedings described above based on our belief that liabilities, while possible, are not probable. Further, except as described above, any possible loss or range of loss in these matters cannot be reasonably estimated at this time. We are engaged in legal actions not described above arising in the ordinary course of business and, while there can be no assurance of favorable outcomes, we believe that the ultimate outcome of these actions will not have a material adverse effect on our operating results, liquidity or financial position.\n", + "19\n", + "NVIDIA Corporation and Subsidiaries\n", + "Notes to Condensed Consolidated Financial Statements (Continued)\n", + "(Unaudited)\n", + "Note 13 - Shareholders’ Equity \n", + "Capital Return Program \n", + "During the first quarter of fiscal year 2025, we repurchased 9.9 million shares of our common stock for $8.0 billion. We did not repurchase any shares during the first quarter of fiscal year 2024. As of April 28, 2024, we were authorized, subject to certain specifications, to repurchase up to $14.5 billion additional shares of our common stock. Our share repurchase program aims to offset dilution from shares issued to employees. We may pursue additional share repurchases as we weigh market factors and other investment opportunities.\n", + "From April 29, 2024 through May 24, 2024, we repurchased 2.3 million shares for $2.1 billion pursuant to a Rule 10b5-1 trading plan.\n", + "During the first quarter of fiscal years 2025 and 2024, we paid $98 million and $99 million in cash dividends to our shareholders, respectively. Our cash dividend program and the payment of future cash dividends under that program are subject to our Board of Directors' continuing determination that the dividend program and the declaration of dividends thereunder are in the best interests of our shareholders.\n", + "Note 14 - Segment Information\n", + "Our Chief Executive Officer is our chief operating decision maker, or CODM, and reviews financial information presented on an operating segment basis for purposes of making decisions and assessing financial performance.\n", + "The Compute & Networking segment includes our Data Center accelerated computing platform; networking; automotive artificial intelligence, or AI, Cockpit, autonomous driving development agreements, and autonomous vehicle solutions; electric vehicle computing platforms; Jetson for robotics and other embedded platforms; NVIDIA AI Enterprise and other software; and DGX Cloud.\n", + "The Graphics segment includes GeForce GPUs for gaming and PCs, the GeForce NOW game streaming service and related infrastructure, and solutions for gaming platforms; Quadro/NVIDIA RTX GPUs for enterprise workstation graphics; virtual GPU software for cloud-based visual and virtual computing; automotive platforms for infotainment systems; and Omniverse Enterprise software for building and operating 3D internet applications.\n", + "Operating results by segment include costs or expenses directly attributable to each segment, and costs or expenses that are leveraged across our unified architecture and therefore allocated between our two segments.\n", + "The “All Other” category includes the expenses that our CODM does not assign to either Compute & Networking or Graphics for purposes of making operating decisions or assessing financial performance. The expenses include stock-based compensation expense, corporate infrastructure and support costs, acquisition-related and other costs, and other non-recurring charges and benefits that our CODM deems to be enterprise in nature.\n", + "Our CODM does not review any information regarding total assets on a reportable segment basis. Depreciation and amortization expenses directly attributable to each reportable segment are included in operating results for each segment. However, our CODM does not evaluate depreciation and amortization expense by operating segment and, therefore, it is not separately presented. The accounting policies for segment reporting are the same as for our consolidated financial statements. The table below presents details of our reportable segments and the “All Other” category.\n", + " \tCompute & Networking\t\tGraphics\t\tAll Other\t\tConsolidated\n", + " \t(In millions)\n", + "Three Months Ended Apr 28, 2024\n", + " \t\t \t\t \t\t \n", + "Revenue\t$\t22,675 \t\t\t$\t3,369 \t\t\t$\t— \t\t\t$\t26,044 \t\n", + "Operating income (loss)\t$\t17,047 \t\t\t$\t1,241 \t\t\t$\t(1,379)\t\t\t$\t16,909 \t\n", + "Three Months Ended Apr 30, 2023\n", + " \t\t \t\t \t\t \n", + "Revenue\t$\t4,460 \t\t\t$\t2,732 \t\t\t$\t— \t\t\t$\t7,192 \t\n", + "Operating income (loss)\t$\t2,160 \t\t\t$\t1,046 \t\t\t$\t(1,066)\t\t\t$\t2,140 \t\n", + " \n", + "\n", + "\"\"\"\n", + "\n", + "# Add\n", + "\n", + "\n", + "def cost_reduction_analyst():\n", + " return \"\"\"\n", + "\n", + " You are a Cost Reduction Analyst. \n", + " Your task is to thoroughly analyze NVIDIA's SEC 10-K filings to identify areas where the company can reduce expenditures. Focus on evaluating operating expenses, administrative costs, research and development (R&D) expenditures, and capital expenditures. Look for patterns of excessive spending, inefficiencies, and opportunities for cost savings. Provide a detailed report outlining specific areas where costs can be cut and suggest practical measures for achieving these reductions.\n", + " \n", + " When finished make a call to the phone number provided and summarize your findings to the person on the other end of the line.\n", + "\n", + " \"\"\"\n", + "\n", + "\n", + "def revenue_maximalist_analyst():\n", + " return \"\"\"\n", + "\n", + " You are a Revenue Maximization Analyst. \n", + " Your task is to examine NVIDIA's SEC 10-K filings to identify opportunities to maximize revenues. Analyze revenue streams from different product lines, geographical markets, and customer segments. Look for underperforming areas, untapped markets, and potential for price adjustments. Provide a comprehensive report on strategies to increase revenues, such as expanding product offerings, entering new markets, or optimizing pricing strategies.\n", + "\n", + " \"\"\"\n", + "\n", + "\n", + "def operational_efficiency():\n", + " return \"\"\"\n", + " You are an Operational Efficiency and Cost Control Specialist. \n", + " Your task is to review NVIDIA's SEC 10-K filings to evaluate the company's operational efficiency and identify opportunities for cost control. Focus on areas such as supply chain management, manufacturing processes, and inventory management. Look for inefficiencies, bottlenecks, and areas where costs can be controlled without compromising quality. Provide a detailed analysis and recommendations for improving operational efficiency and reducing costs.\n", + "\n", + " \"\"\"\n", + "\n", + "\n", + "def strategic_investment_analyst():\n", + " return \"\"\"\n", + "\n", + " You are a Strategic Investment Analyst. \n", + " Your task is to analyze NVIDIA's SEC 10-K filings to evaluate the company's investment strategies and identify areas where expenditures can be optimized. Focus on R&D investments, capital projects, and acquisition strategies. Assess the return on investment (ROI) for significant expenditures and identify any investments that are not yielding expected returns. Provide a detailed report on how NVIDIA can reallocate or reduce investments to maximize financial performance.\n", + "\n", + " \"\"\"\n", + "\n", + "\n", + "def sales_marketing_agent_prompt():\n", + " return \"\"\"\n", + " You are a Sales and Marketing Optimization Specialist. Your task is to examine NVIDIA's SEC 10-K filings to evaluate the effectiveness of the company's sales and marketing efforts and identify areas where expenditures can be reduced while maximizing revenue. Analyze marketing expenses, sales strategies, and customer acquisition costs. Look for areas where spending can be optimized and suggest strategies for increasing marketing efficiency and sales effectiveness. Provide a comprehensive report with actionable recommendations.\n", + "\n", + " These prompts will help each agent focus on specific aspects of NVIDIA's expenditures and revenue opportunities, ensuring a thorough analysis aimed at cutting costs and maximizing revenues.\n", + "\n", + " \"\"\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", + "# Initialize the director agent\n", + "cost_reduction_agent = Agent(\n", + " agent_name=\"Cost Reduction Analyst\",\n", + " system_prompt=cost_reduction_analyst(),\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"cost_reduction_analyst.json\",\n", + ")\n", + "\n", + "# Initialize the agents\n", + "revenue_maximalist_agent = Agent(\n", + " agent_name=\"Revenue Maximization Analyst\",\n", + " system_prompt=revenue_maximalist_analyst(),\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"revenue_maximalist_analyst.json\",\n", + "\n", + ")\n", + "\n", + "cost_control_agent = Agent(\n", + " agent_name=\"Operational Efficiency and Cost Control Specialist\",\n", + " system_prompt=operational_efficiency(),\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"operational_efficiency.json\",\n", + "\n", + ")\n", + "\n", + "investment_analyst_agent = Agent(\n", + " agent_name=\"Strategic Investment Analyst\",\n", + " system_prompt=strategic_investment_analyst(),\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"strategic_investment_analyst.json\",\n", + ")\n", + "\n", + "sales_marketing_agent = Agent(\n", + " agent_name=\"Sales and Marketing Optimization Specialist\",\n", + " system_prompt=sales_marketing_agent_prompt(),\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"sales_marketing_agent.json\",\n", + ")\n", + "\n", + "\n", + "final_agent = Agent(\n", + " agent_name=\"Final Agent\",\n", + " system_prompt=\"You are the final agent. Please summarize the findings of the previous agents and provide a comprehensive report on how NVIDIA can optimize its financial performance. When finished make a call to the phone number provided and summarize your findings to the person on the other end of the line. Summarize the points such as how to lower the costs and increase the revenue.\",\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " state_save_file_type=\"json\",\n", + ")\n", + "\n", + "\n", + "agents = [\n", + " cost_reduction_agent,\n", + " revenue_maximalist_agent,\n", + " cost_control_agent,\n", + " investment_analyst_agent,\n", + " sales_marketing_agent,\n", + "]\n", + "\n", + "\n", + "# Swarm\n", + "swarm = MixtureOfAgents(\n", + " name=\"Mixture of Accountants\",\n", + " agents=agents,\n", + " layers=1,\n", + " final_agent=final_agent,\n", + ")\n", + "\n", + "\n", + "# Run the swarm\n", + "out = swarm.run(\n", + " f\"Analyze the following Nvidia financial data and locate unnecessary expenditures: {SEC_FILLING}\"\n", + ")\n", + "print(out)\n" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/playground/structs/multi_agent_collaboration/mixture_of_agents/agent_ops_moa.py b/playground/structs/multi_agent_collaboration/mixture_of_agents/agent_ops_moa.py new file mode 100644 index 00000000..5b7df470 --- /dev/null +++ b/playground/structs/multi_agent_collaboration/mixture_of_agents/agent_ops_moa.py @@ -0,0 +1,451 @@ +from swarms import Agent, OpenAIChat +from swarms.structs.mixture_of_agents import MixtureOfAgents +from playground.memory.chromadb_example import ChromaDB + + +SEC_DATA = """ +Where You Can Find More Information +Investors and others should note that we announce material financial information to our investors using our investor relations website, press releases, SEC filings and public conference calls and webcasts. We also use the following social media channels as a means of disclosing information about the company, our products, our planned financial and other announcements and attendance at upcoming investor and industry conferences, and other matters, and for complying with our disclosure obligations under Regulation FD: +NVIDIA Corporate Blog (http://blogs.nvidia.com) +NVIDIA Technical Blog (http://developer.nvidia.com/blog/) +NVIDIA LinkedIn Page (http://www.linkedin.com/company/nvidia) +NVIDIA Facebook Page (https://www.facebook.com/nvidia) +NVIDIA Instagram Page (https://www.instagram.com/nvidia) +NVIDIA X Account (https://x.com/nvidia) +In addition, investors and others can view NVIDIA videos on YouTube (https://www.YouTube.com/nvidia). +The information we post through these social media channels may be deemed material. Accordingly, investors should monitor these accounts and the blog, in addition to following our press releases, SEC filings and public conference calls and webcasts. This list may be updated from time to time. The information we post through these channels is not a part of this Quarterly Report on Form 10-Q. These channels may be updated from time to time on NVIDIA's investor relations website. +2 + +Part I. Financial Information +Item 1. Financial Statements (Unaudited) + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Income +(In millions, except per share data) +(Unaudited) + + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +Revenue $ 26,044 $ 7,192 +Cost of revenue 5,638 2,544 +Gross profit 20,406 4,648 +Operating expenses +Research and development 2,720 1,875 +Sales, general and administrative 777 633 +Total operating expenses 3,497 2,508 +Operating income 16,909 2,140 +Interest income 359 150 +Interest expense (64) (66) +Other, net 75 (15) +Other income (expense), net +370 69 +Income before income tax 17,279 2,209 +Income tax expense 2,398 166 +Net income $ 14,881 $ 2,043 +Net income per share: +Basic $ 6.04 $ 0.83 +Diluted $ 5.98 $ 0.82 +Weighted average shares used in per share computation: +Basic 2,462 2,470 +Diluted 2,489 2,490 + + +See accompanying Notes to Condensed Consolidated Financial Statements. +3 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Comprehensive Income +(In millions) +(Unaudited) + Three Months Ended + Apr 28, 2024 Apr 30, 2023 + +Net income $ 14,881 $ 2,043 +Other comprehensive loss, net of tax +Available-for-sale securities: +Net change in unrealized gain (loss) (128) 17 +Cash flow hedges: +Net change in unrealized loss (4) (13) +Reclassification adjustments for net realized loss included in net income (4) (11) +Net change in unrealized loss (8) (24) +Other comprehensive loss, net of tax (136) (7) +Total comprehensive income $ 14,745 $ 2,036 + + +See accompanying Notes to Condensed Consolidated Financial Statements. + +4 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Balance Sheets +(In millions) +(Unaudited) + Apr 28, 2024 Jan 28, 2024 +Assets +Current assets: +Cash and cash equivalents $ 7,587 $ 7,280 +Marketable securities 23,851 18,704 +Accounts receivable, net 12,365 9,999 +Inventories 5,864 5,282 +Prepaid expenses and other current assets 4,062 3,080 +Total current assets 53,729 44,345 +Property and equipment, net 4,006 3,914 +Operating lease assets 1,532 1,346 +Goodwill 4,453 4,430 +Intangible assets, net 986 1,112 +Deferred income tax assets 7,798 6,081 +Other assets 4,568 4,500 +Total assets $ 77,072 $ 65,728 +Liabilities and Shareholders' Equity +Current liabilities: +Accounts payable $ 2,715 $ 2,699 +Accrued and other current liabilities 11,258 6,682 +Short-term debt 1,250 1,250 +Total current liabilities 15,223 10,631 +Long-term debt 8,460 8,459 +Long-term operating lease liabilities 1,281 1,119 +Other long-term liabilities 2,966 2,541 +Total liabilities 27,930 22,750 +Commitments and contingencies - see Note 12 +Shareholders’ equity: +Preferred stock — — +Common stock 2 2 +Additional paid-in capital 12,651 13,132 +Accumulated other comprehensive income (loss) (109) 27 +Retained earnings 36,598 29,817 +Total shareholders' equity 49,142 42,978 +Total liabilities and shareholders' equity $ 77,072 $ 65,728 + + +See accompanying Notes to Condensed Consolidated Financial Statements. + +5 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Shareholders' Equity +For the Three Months Ended April 28, 2024 and April 30, 2023 +(Unaudited) +Common Stock +Outstanding Additional Paid-in Capital Accumulated Other Comprehensive Income (Loss) Retained Earnings Total Shareholders' Equity +Shares Amount +(In millions, except per share data) +Balances, Jan 28, 2024 2,464 $ 2 $ 13,132 $ 27 $ 29,817 $ 42,978 +Net income — — — — 14,881 14,881 +Other comprehensive loss — — — (136) — (136) +Issuance of common stock from stock plans 7 — 285 — — 285 +Tax withholding related to vesting of restricted stock units (2) — (1,752) — — (1,752) +Shares repurchased (10) — (33) — (8,002) (8,035) +Cash dividends declared and paid ($0.04 per common share) +— — — — (98) (98) +Stock-based compensation — — 1,019 — — 1,019 +Balances, Apr 28, 2024 2,459 $ 2 $ 12,651 $ (109) $ 36,598 $ 49,142 +Balances, Jan 29, 2023 2,466 $ 2 $ 11,971 $ (43) $ 10,171 $ 22,101 +Net income — — — — 2,043 2,043 +Other comprehensive loss — — — (7) — (7) +Issuance of common stock from stock plans 9 — 246 — — 246 +Tax withholding related to vesting of restricted stock units (2) — (507) — — (507) +Cash dividends declared and paid ($0.04 per common share) +— — — — (99) (99) +Stock-based compensation — — 743 — — 743 +Balances, Apr 30, 2023 2,473 $ 2 $ 12,453 $ (50) $ 12,115 $ 24,520 + +See accompanying Notes to Condensed Consolidated Financial Statements. +6 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Cash Flows +(In millions) +(Unaudited) + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +Cash flows from operating activities: +Net income $ 14,881 $ 2,043 +Adjustments to reconcile net income to net cash provided by operating activities: +Stock-based compensation expense 1,011 735 +Depreciation and amortization 410 384 +Realized and unrealized (gains) losses on investments in non-affiliated entities, net (69) 14 +Deferred income taxes (1,577) (1,135) +Other (145) (34) +Changes in operating assets and liabilities, net of acquisitions: +Accounts receivable (2,366) (252) +Inventories (577) 566 +Prepaid expenses and other assets (726) (215) +Accounts payable (22) 11 +Accrued and other current liabilities 4,202 689 +Other long-term liabilities 323 105 +Net cash provided by operating activities 15,345 2,911 +Cash flows from investing activities: +Proceeds from maturities of marketable securities 4,004 2,512 +Proceeds from sales of marketable securities 149 — +Purchases of marketable securities (9,303) (2,801) +Purchases related to property and equipment and intangible assets (369) (248) +Acquisitions, net of cash acquired (39) (83) +Investments in non-affiliated entities (135) (221) +Net cash used in investing activities (5,693) (841) +Cash flows from financing activities: +Proceeds related to employee stock plans 285 246 +Payments related to repurchases of common stock (7,740) — +Payments related to tax on restricted stock units (1,752) (507) +Dividends paid (98) (99) +Principal payments on property and equipment and intangible assets (40) (20) +Net cash used in financing activities (9,345) (380) +Change in cash and cash equivalents 307 1,690 +Cash and cash equivalents at beginning of period 7,280 3,389 +Cash and cash equivalents at end of period $ 7,587 $ 5,079 + +See accompanying Notes to Condensed Consolidated Financial Statements. +7 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements +(Unaudited) + + +Note 1 - Summary of Significant Accounting Policies +Basis of Presentation +The accompanying unaudited condensed consolidated financial statements were prepared in accordance with accounting principles generally accepted in the United States of America, or U.S. GAAP, for interim financial information and with the instructions to Form 10-Q and Article 10 of Securities and Exchange Commission, or SEC, Regulation S-X. The January 28, 2024 consolidated balance sheet was derived from our audited consolidated financial statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024, as filed with the SEC, but does not include all disclosures required by U.S. GAAP. In the opinion of management, all adjustments, consisting only of normal recurring adjustments considered necessary for a fair statement of results of operations and financial position, have been included. The results for the interim periods presented are not necessarily indicative of the results expected for any future period. The following information should be read in conjunction with the audited consolidated financial statements and notes thereto included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024. +Significant Accounting Policies +There have been no material changes to our significant accounting policies disclosed in Note 1 - Organization and Summary of Significant Accounting Policies, of the Notes to the Consolidated Financial Statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024. +Fiscal Year +We operate on a 52- or 53-week year, ending on the last Sunday in January. Fiscal years 2025 and 2024 are both 52-week years. The first quarters of fiscal years 2025 and 2024 were both 13-week quarters. +Principles of Consolidation +Our condensed consolidated financial statements include the accounts of NVIDIA Corporation and our wholly-owned subsidiaries. All intercompany balances and transactions have been eliminated in consolidation. +Use of Estimates +The preparation of financial statements in conformity with U.S. GAAP requires management to make estimates and assumptions that affect the reported amounts of assets and liabilities and disclosures of contingent assets and liabilities at the date of the financial statements and the reported amounts of revenue and expenses during the reporting period. Actual results could differ materially from our estimates. On an on-going basis, we evaluate our estimates, including those related to revenue recognition, cash equivalents and marketable securities, accounts receivable, inventories and product purchase commitments, income taxes, goodwill, stock-based compensation, litigation, investigation and settlement costs, property, plant, and equipment, and other contingencies. These estimates are based on historical facts and various other assumptions that we believe are reasonable. +Recently Issued Accounting Pronouncements +Recent Accounting Pronouncements Not Yet Adopted +In November 2023, the Financial Accounting Standards Board, or FASB, issued a new accounting standard to provide for additional disclosures about significant expenses in operating segments. The standard is effective for our annual reporting starting with fiscal year 2025 and for interim period reporting starting in fiscal year 2026 retrospectively. We are currently evaluating the impact of this standard on our Consolidated Financial Statements. +In December 2023, the FASB issued a new accounting standard which provides for new and updated income tax disclosures, including disaggregation of rate reconciliation and income taxes paid. The standard is effective for annual periods beginning after December 15, 2024. Early adoption is permitted and should be applied prospectively, with retrospective application permitted. We expect to adopt this standard in our annual reporting starting with fiscal year 2026. We are currently evaluating the impact of this standard on our Consolidated Financial Statements. + + + +8 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 2 - Leases +Our lease obligations primarily consist of operating leases for our headquarters complex, domestic and international office facilities, and data center space, with lease periods expiring between fiscal years 2025 and 2035. +Future minimum lease payments under our non-cancelable operating leases as of April 28, 2024 were as follows: +Operating Lease Obligations + (In millions) +Fiscal Year: +2025 (excluding first quarter of fiscal year 2025) +$ 221 +2026 306 +2027 290 +2028 270 +2029 236 +2030 and thereafter +410 +Total 1,733 +Less imputed interest 206 +Present value of net future minimum lease payments 1,527 +Less short-term operating lease liabilities 246 +Long-term operating lease liabilities $ 1,281 + +In addition, we have operating leases, primarily for our data centers, that are expected to commence during fiscal year 2025 with lease terms of 2 to 11 years for $923 million. +Operating lease expenses were $80 million and $59 million for the first quarter of fiscal years 2025 and 2024, respectively. Short-term and variable lease expenses for the first quarter of fiscal years 2025 and 2024 were not significant. +Other information related to leases was as follows: +Three Months Ended +Apr 28, 2024 Apr 30, 2023 + (In millions) +Supplemental cash flows information +Operating cash flows used for operating leases $ 69 $ 61 +Operating lease assets obtained in exchange for lease obligations 250 106 + +As of April 28, 2024, our operating leases had a weighted average remaining lease term of 6.3 years and a weighted average discount rate of 3.89%. As of January 28, 2024, our operating leases had a weighted average remaining lease term of 6.1 years and a weighted average discount rate of 3.76%. +9 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 3 - Stock-Based Compensation +Our stock-based compensation expense is associated with restricted stock units, or RSUs, performance stock units that are based on our corporate financial performance targets, or PSUs, performance stock units that are based on market conditions, or market-based PSUs, and our employee stock purchase plan, or ESPP. +Our Condensed Consolidated Statements of Income include stock-based compensation expense, net of amounts capitalized into inventory and subsequently recognized to cost of revenue, as follows: + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +(In millions) +Cost of revenue $ 36 $ 27 +Research and development 727 524 +Sales, general and administrative 248 184 +Total $ 1,011 $ 735 + +Equity Award Activity +The following is a summary of our equity award transactions under our equity incentive plans: +RSUs, PSUs, and Market-based PSUs Outstanding + Number of Shares Weighted Average Grant-Date Fair Value Per Share +(In millions, except per share data) +Balances, Jan 28, 2024 37 $ 245.94 +Granted 7 $ 801.79 +Vested (6) $ 176.59 +Balances, Apr 28, 2024 38 $ 361.45 + +As of April 28, 2024, there was $13.2 billion of aggregate unearned stock-based compensation expense. This amount is expected to be recognized over a weighted average period of 2.6 years for RSUs, PSUs, and market-based PSUs, and 0.8 years for ESPP. +Note 4 - Net Income Per Share +The following is a reconciliation of the denominator of the basic and diluted net income per share computations for the periods presented: + + +""" + + +memory = ChromaDB( + output_dir="scp", + docs_folder="artifacts", + n_results=500, +) + +llm = OpenAIChat( + max_tokens=3000, +) + +# Initialize the director agent +# Initialize the director agent +director = Agent( + agent_name="Director", + system_prompt="Directs the tasks for the accountants", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="director.json", +) + +# Initialize accountant 1 +accountant1 = Agent( + agent_name="Accountant1", + system_prompt="Prepares financial statements", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="accountant1.json", +) + +# Initialize accountant 2 +accountant2 = Agent( + agent_name="Accountant2", + system_prompt="Audits financial records", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="accountant2.json", +) + +# Initialize 8 more specialized agents +balance_sheet_analyzer = Agent( + agent_name="BalanceSheetAnalyzer", + system_prompt="Analyzes balance sheets", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="balance_sheet_analyzer.json", +) + +income_statement_analyzer = Agent( + agent_name="IncomeStatementAnalyzer", + system_prompt="Analyzes income statements", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="income_statement_analyzer.json", +) + +cash_flow_analyzer = Agent( + agent_name="CashFlowAnalyzer", + system_prompt="Analyzes cash flow statements", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="cash_flow_analyzer.json", +) + +financial_ratio_calculator = Agent( + agent_name="FinancialRatioCalculator", + system_prompt="Calculates financial ratios", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="financial_ratio_calculator.json", +) + +tax_preparer = Agent( + agent_name="TaxPreparer", + system_prompt="Prepares tax returns", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="tax_preparer.json", +) + +payroll_processor = Agent( + agent_name="PayrollProcessor", + system_prompt="Processes payroll", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="payroll_processor.json", +) + +inventory_manager = Agent( + agent_name="InventoryManager", + system_prompt="Manages inventory", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="inventory_manager.json", +) + +budget_planner = Agent( + agent_name="BudgetPlanner", + system_prompt="Plans budgets", + llm=llm, + agent_ops_on=True, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="budget_planner.json", +) + +# Create a list of agents +agents = [ + director, + balance_sheet_analyzer, + income_statement_analyzer, + cash_flow_analyzer, + financial_ratio_calculator, + tax_preparer, + payroll_processor, + inventory_manager, + budget_planner, +] + +# Swarm +swarm = MixtureOfAgents( + name="Mixture of Accountants", + agents=agents, + layers=3, + final_agent=director, +) + + +# Run the swarm +out = swarm.run( + f"Analyze the following Nvidia financial data and locate unnecessary expenditures: {SEC_DATA}" +) +print(out) diff --git a/playground/structs/multi_agent_collaboration/mixture_of_agents/moa_with_scp.py b/playground/structs/multi_agent_collaboration/mixture_of_agents/moa_with_scp.py new file mode 100644 index 00000000..1596bfff --- /dev/null +++ b/playground/structs/multi_agent_collaboration/mixture_of_agents/moa_with_scp.py @@ -0,0 +1,441 @@ +from swarms import Agent, OpenAIChat +from swarms.structs.mixture_of_agents import MixtureOfAgents +from playground.memory.chromadb_example import ChromaDB + + +SEC_DATA = """ +Where You Can Find More Information +Investors and others should note that we announce material financial information to our investors using our investor relations website, press releases, SEC filings and public conference calls and webcasts. We also use the following social media channels as a means of disclosing information about the company, our products, our planned financial and other announcements and attendance at upcoming investor and industry conferences, and other matters, and for complying with our disclosure obligations under Regulation FD: +NVIDIA Corporate Blog (http://blogs.nvidia.com) +NVIDIA Technical Blog (http://developer.nvidia.com/blog/) +NVIDIA LinkedIn Page (http://www.linkedin.com/company/nvidia) +NVIDIA Facebook Page (https://www.facebook.com/nvidia) +NVIDIA Instagram Page (https://www.instagram.com/nvidia) +NVIDIA X Account (https://x.com/nvidia) +In addition, investors and others can view NVIDIA videos on YouTube (https://www.YouTube.com/nvidia). +The information we post through these social media channels may be deemed material. Accordingly, investors should monitor these accounts and the blog, in addition to following our press releases, SEC filings and public conference calls and webcasts. This list may be updated from time to time. The information we post through these channels is not a part of this Quarterly Report on Form 10-Q. These channels may be updated from time to time on NVIDIA's investor relations website. +2 + +Part I. Financial Information +Item 1. Financial Statements (Unaudited) + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Income +(In millions, except per share data) +(Unaudited) + + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +Revenue $ 26,044 $ 7,192 +Cost of revenue 5,638 2,544 +Gross profit 20,406 4,648 +Operating expenses +Research and development 2,720 1,875 +Sales, general and administrative 777 633 +Total operating expenses 3,497 2,508 +Operating income 16,909 2,140 +Interest income 359 150 +Interest expense (64) (66) +Other, net 75 (15) +Other income (expense), net +370 69 +Income before income tax 17,279 2,209 +Income tax expense 2,398 166 +Net income $ 14,881 $ 2,043 +Net income per share: +Basic $ 6.04 $ 0.83 +Diluted $ 5.98 $ 0.82 +Weighted average shares used in per share computation: +Basic 2,462 2,470 +Diluted 2,489 2,490 + + +See accompanying Notes to Condensed Consolidated Financial Statements. +3 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Comprehensive Income +(In millions) +(Unaudited) + Three Months Ended + Apr 28, 2024 Apr 30, 2023 + +Net income $ 14,881 $ 2,043 +Other comprehensive loss, net of tax +Available-for-sale securities: +Net change in unrealized gain (loss) (128) 17 +Cash flow hedges: +Net change in unrealized loss (4) (13) +Reclassification adjustments for net realized loss included in net income (4) (11) +Net change in unrealized loss (8) (24) +Other comprehensive loss, net of tax (136) (7) +Total comprehensive income $ 14,745 $ 2,036 + + +See accompanying Notes to Condensed Consolidated Financial Statements. + +4 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Balance Sheets +(In millions) +(Unaudited) + Apr 28, 2024 Jan 28, 2024 +Assets +Current assets: +Cash and cash equivalents $ 7,587 $ 7,280 +Marketable securities 23,851 18,704 +Accounts receivable, net 12,365 9,999 +Inventories 5,864 5,282 +Prepaid expenses and other current assets 4,062 3,080 +Total current assets 53,729 44,345 +Property and equipment, net 4,006 3,914 +Operating lease assets 1,532 1,346 +Goodwill 4,453 4,430 +Intangible assets, net 986 1,112 +Deferred income tax assets 7,798 6,081 +Other assets 4,568 4,500 +Total assets $ 77,072 $ 65,728 +Liabilities and Shareholders' Equity +Current liabilities: +Accounts payable $ 2,715 $ 2,699 +Accrued and other current liabilities 11,258 6,682 +Short-term debt 1,250 1,250 +Total current liabilities 15,223 10,631 +Long-term debt 8,460 8,459 +Long-term operating lease liabilities 1,281 1,119 +Other long-term liabilities 2,966 2,541 +Total liabilities 27,930 22,750 +Commitments and contingencies - see Note 12 +Shareholders’ equity: +Preferred stock — — +Common stock 2 2 +Additional paid-in capital 12,651 13,132 +Accumulated other comprehensive income (loss) (109) 27 +Retained earnings 36,598 29,817 +Total shareholders' equity 49,142 42,978 +Total liabilities and shareholders' equity $ 77,072 $ 65,728 + + +See accompanying Notes to Condensed Consolidated Financial Statements. + +5 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Shareholders' Equity +For the Three Months Ended April 28, 2024 and April 30, 2023 +(Unaudited) +Common Stock +Outstanding Additional Paid-in Capital Accumulated Other Comprehensive Income (Loss) Retained Earnings Total Shareholders' Equity +Shares Amount +(In millions, except per share data) +Balances, Jan 28, 2024 2,464 $ 2 $ 13,132 $ 27 $ 29,817 $ 42,978 +Net income — — — — 14,881 14,881 +Other comprehensive loss — — — (136) — (136) +Issuance of common stock from stock plans 7 — 285 — — 285 +Tax withholding related to vesting of restricted stock units (2) — (1,752) — — (1,752) +Shares repurchased (10) — (33) — (8,002) (8,035) +Cash dividends declared and paid ($0.04 per common share) +— — — — (98) (98) +Stock-based compensation — — 1,019 — — 1,019 +Balances, Apr 28, 2024 2,459 $ 2 $ 12,651 $ (109) $ 36,598 $ 49,142 +Balances, Jan 29, 2023 2,466 $ 2 $ 11,971 $ (43) $ 10,171 $ 22,101 +Net income — — — — 2,043 2,043 +Other comprehensive loss — — — (7) — (7) +Issuance of common stock from stock plans 9 — 246 — — 246 +Tax withholding related to vesting of restricted stock units (2) — (507) — — (507) +Cash dividends declared and paid ($0.04 per common share) +— — — — (99) (99) +Stock-based compensation — — 743 — — 743 +Balances, Apr 30, 2023 2,473 $ 2 $ 12,453 $ (50) $ 12,115 $ 24,520 + +See accompanying Notes to Condensed Consolidated Financial Statements. +6 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Cash Flows +(In millions) +(Unaudited) + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +Cash flows from operating activities: +Net income $ 14,881 $ 2,043 +Adjustments to reconcile net income to net cash provided by operating activities: +Stock-based compensation expense 1,011 735 +Depreciation and amortization 410 384 +Realized and unrealized (gains) losses on investments in non-affiliated entities, net (69) 14 +Deferred income taxes (1,577) (1,135) +Other (145) (34) +Changes in operating assets and liabilities, net of acquisitions: +Accounts receivable (2,366) (252) +Inventories (577) 566 +Prepaid expenses and other assets (726) (215) +Accounts payable (22) 11 +Accrued and other current liabilities 4,202 689 +Other long-term liabilities 323 105 +Net cash provided by operating activities 15,345 2,911 +Cash flows from investing activities: +Proceeds from maturities of marketable securities 4,004 2,512 +Proceeds from sales of marketable securities 149 — +Purchases of marketable securities (9,303) (2,801) +Purchases related to property and equipment and intangible assets (369) (248) +Acquisitions, net of cash acquired (39) (83) +Investments in non-affiliated entities (135) (221) +Net cash used in investing activities (5,693) (841) +Cash flows from financing activities: +Proceeds related to employee stock plans 285 246 +Payments related to repurchases of common stock (7,740) — +Payments related to tax on restricted stock units (1,752) (507) +Dividends paid (98) (99) +Principal payments on property and equipment and intangible assets (40) (20) +Net cash used in financing activities (9,345) (380) +Change in cash and cash equivalents 307 1,690 +Cash and cash equivalents at beginning of period 7,280 3,389 +Cash and cash equivalents at end of period $ 7,587 $ 5,079 + +See accompanying Notes to Condensed Consolidated Financial Statements. +7 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements +(Unaudited) + + +Note 1 - Summary of Significant Accounting Policies +Basis of Presentation +The accompanying unaudited condensed consolidated financial statements were prepared in accordance with accounting principles generally accepted in the United States of America, or U.S. GAAP, for interim financial information and with the instructions to Form 10-Q and Article 10 of Securities and Exchange Commission, or SEC, Regulation S-X. The January 28, 2024 consolidated balance sheet was derived from our audited consolidated financial statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024, as filed with the SEC, but does not include all disclosures required by U.S. GAAP. In the opinion of management, all adjustments, consisting only of normal recurring adjustments considered necessary for a fair statement of results of operations and financial position, have been included. The results for the interim periods presented are not necessarily indicative of the results expected for any future period. The following information should be read in conjunction with the audited consolidated financial statements and notes thereto included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024. +Significant Accounting Policies +There have been no material changes to our significant accounting policies disclosed in Note 1 - Organization and Summary of Significant Accounting Policies, of the Notes to the Consolidated Financial Statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024. +Fiscal Year +We operate on a 52- or 53-week year, ending on the last Sunday in January. Fiscal years 2025 and 2024 are both 52-week years. The first quarters of fiscal years 2025 and 2024 were both 13-week quarters. +Principles of Consolidation +Our condensed consolidated financial statements include the accounts of NVIDIA Corporation and our wholly-owned subsidiaries. All intercompany balances and transactions have been eliminated in consolidation. +Use of Estimates +The preparation of financial statements in conformity with U.S. GAAP requires management to make estimates and assumptions that affect the reported amounts of assets and liabilities and disclosures of contingent assets and liabilities at the date of the financial statements and the reported amounts of revenue and expenses during the reporting period. Actual results could differ materially from our estimates. On an on-going basis, we evaluate our estimates, including those related to revenue recognition, cash equivalents and marketable securities, accounts receivable, inventories and product purchase commitments, income taxes, goodwill, stock-based compensation, litigation, investigation and settlement costs, property, plant, and equipment, and other contingencies. These estimates are based on historical facts and various other assumptions that we believe are reasonable. +Recently Issued Accounting Pronouncements +Recent Accounting Pronouncements Not Yet Adopted +In November 2023, the Financial Accounting Standards Board, or FASB, issued a new accounting standard to provide for additional disclosures about significant expenses in operating segments. The standard is effective for our annual reporting starting with fiscal year 2025 and for interim period reporting starting in fiscal year 2026 retrospectively. We are currently evaluating the impact of this standard on our Consolidated Financial Statements. +In December 2023, the FASB issued a new accounting standard which provides for new and updated income tax disclosures, including disaggregation of rate reconciliation and income taxes paid. The standard is effective for annual periods beginning after December 15, 2024. Early adoption is permitted and should be applied prospectively, with retrospective application permitted. We expect to adopt this standard in our annual reporting starting with fiscal year 2026. We are currently evaluating the impact of this standard on our Consolidated Financial Statements. + + + +8 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 2 - Leases +Our lease obligations primarily consist of operating leases for our headquarters complex, domestic and international office facilities, and data center space, with lease periods expiring between fiscal years 2025 and 2035. +Future minimum lease payments under our non-cancelable operating leases as of April 28, 2024 were as follows: +Operating Lease Obligations + (In millions) +Fiscal Year: +2025 (excluding first quarter of fiscal year 2025) +$ 221 +2026 306 +2027 290 +2028 270 +2029 236 +2030 and thereafter +410 +Total 1,733 +Less imputed interest 206 +Present value of net future minimum lease payments 1,527 +Less short-term operating lease liabilities 246 +Long-term operating lease liabilities $ 1,281 + +In addition, we have operating leases, primarily for our data centers, that are expected to commence during fiscal year 2025 with lease terms of 2 to 11 years for $923 million. +Operating lease expenses were $80 million and $59 million for the first quarter of fiscal years 2025 and 2024, respectively. Short-term and variable lease expenses for the first quarter of fiscal years 2025 and 2024 were not significant. +Other information related to leases was as follows: +Three Months Ended +Apr 28, 2024 Apr 30, 2023 + (In millions) +Supplemental cash flows information +Operating cash flows used for operating leases $ 69 $ 61 +Operating lease assets obtained in exchange for lease obligations 250 106 + +As of April 28, 2024, our operating leases had a weighted average remaining lease term of 6.3 years and a weighted average discount rate of 3.89%. As of January 28, 2024, our operating leases had a weighted average remaining lease term of 6.1 years and a weighted average discount rate of 3.76%. +9 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 3 - Stock-Based Compensation +Our stock-based compensation expense is associated with restricted stock units, or RSUs, performance stock units that are based on our corporate financial performance targets, or PSUs, performance stock units that are based on market conditions, or market-based PSUs, and our employee stock purchase plan, or ESPP. +Our Condensed Consolidated Statements of Income include stock-based compensation expense, net of amounts capitalized into inventory and subsequently recognized to cost of revenue, as follows: + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +(In millions) +Cost of revenue $ 36 $ 27 +Research and development 727 524 +Sales, general and administrative 248 184 +Total $ 1,011 $ 735 + +Equity Award Activity +The following is a summary of our equity award transactions under our equity incentive plans: +RSUs, PSUs, and Market-based PSUs Outstanding + Number of Shares Weighted Average Grant-Date Fair Value Per Share +(In millions, except per share data) +Balances, Jan 28, 2024 37 $ 245.94 +Granted 7 $ 801.79 +Vested (6) $ 176.59 +Balances, Apr 28, 2024 38 $ 361.45 + +As of April 28, 2024, there was $13.2 billion of aggregate unearned stock-based compensation expense. This amount is expected to be recognized over a weighted average period of 2.6 years for RSUs, PSUs, and market-based PSUs, and 0.8 years for ESPP. +Note 4 - Net Income Per Share +The following is a reconciliation of the denominator of the basic and diluted net income per share computations for the periods presented: + + +""" + + +memory = ChromaDB( + output_dir="scp", + docs_folder="artifacts", + n_results=500, +) + +llm = OpenAIChat( + max_tokens=3000, +) + +# Initialize the director agent +# Initialize the director agent +director = Agent( + agent_name="Director", + system_prompt="Directs the tasks for the accountants", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="director.json", +) + +# Initialize accountant 1 +accountant1 = Agent( + agent_name="Accountant1", + system_prompt="Prepares financial statements", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="accountant1.json", +) + +# Initialize accountant 2 +accountant2 = Agent( + agent_name="Accountant2", + system_prompt="Audits financial records", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="accountant2.json", +) + +# Initialize 8 more specialized agents +balance_sheet_analyzer = Agent( + agent_name="BalanceSheetAnalyzer", + system_prompt="Analyzes balance sheets", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="balance_sheet_analyzer.json", +) + +income_statement_analyzer = Agent( + agent_name="IncomeStatementAnalyzer", + system_prompt="Analyzes income statements", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="income_statement_analyzer.json", +) + +cash_flow_analyzer = Agent( + agent_name="CashFlowAnalyzer", + system_prompt="Analyzes cash flow statements", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="cash_flow_analyzer.json", +) + +financial_ratio_calculator = Agent( + agent_name="FinancialRatioCalculator", + system_prompt="Calculates financial ratios", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="financial_ratio_calculator.json", +) + +tax_preparer = Agent( + agent_name="TaxPreparer", + system_prompt="Prepares tax returns", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="tax_preparer.json", +) + +payroll_processor = Agent( + agent_name="PayrollProcessor", + system_prompt="Processes payroll", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="payroll_processor.json", +) + +inventory_manager = Agent( + agent_name="InventoryManager", + system_prompt="Manages inventory", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="inventory_manager.json", +) + +budget_planner = Agent( + agent_name="BudgetPlanner", + system_prompt="Plans budgets", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="budget_planner.json", +) + +# Create a list of agents +agents = [ + director, + balance_sheet_analyzer, + income_statement_analyzer, + cash_flow_analyzer, + financial_ratio_calculator, + tax_preparer, + payroll_processor, + inventory_manager, + budget_planner, +] + +# Swarm +swarm = MixtureOfAgents( + name="Mixture of Accountants", + agents=agents, + layers=3, + final_agent=director, + scp=memory, +) + + +# Run the swarm +out = swarm.run( + f"Analyze the following Nvidia financial data and locate unnecessary expenditures: {SEC_DATA}" +) +print(out) diff --git a/playground/structs/multi_agent_collaboration/swarm_of_ba_agents/agents.py b/playground/structs/multi_agent_collaboration/swarm_of_ba_agents/agents.py new file mode 100644 index 00000000..b01b9982 --- /dev/null +++ b/playground/structs/multi_agent_collaboration/swarm_of_ba_agents/agents.py @@ -0,0 +1,732 @@ +import requests +import json + +import os +from swarms import Agent, MixtureOfAgents, OpenAIChat + +llm = OpenAIChat( + max_tokens=1000, + openai_api_key=os.getenv("OPENAI_API_KEY"), +) + + +SEC_FILLING = """ + + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +Revenue $ 26,044 $ 7,192 +Cost of revenue 5,638 2,544 +Gross profit 20,406 4,648 +Operating expenses +Research and development 2,720 1,875 +Sales, general and administrative 777 633 +Total operating expenses 3,497 2,508 +Operating income 16,909 2,140 +Interest income 359 150 +Interest expense (64) (66) +Other, net 75 (15) +Other income (expense), net +370 69 +Income before income tax 17,279 2,209 +Income tax expense 2,398 166 +Net income $ 14,881 $ 2,043 +Net income per share: +Basic $ 6.04 $ 0.83 +Diluted $ 5.98 $ 0.82 +Weighted average shares used in per share computation: +Basic 2,462 2,470 +Diluted 2,489 2,490 + + +See accompanying Notes to Condensed Consolidated Financial Statements. +3 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Comprehensive Income +(In millions) +(Unaudited) + Three Months Ended + Apr 28, 2024 Apr 30, 2023 + +Net income $ 14,881 $ 2,043 +Other comprehensive loss, net of tax +Available-for-sale securities: +Net change in unrealized gain (loss) (128) 17 +Cash flow hedges: +Net change in unrealized loss (4) (13) +Reclassification adjustments for net realized loss included in net income (4) (11) +Net change in unrealized loss (8) (24) +Other comprehensive loss, net of tax (136) (7) +Total comprehensive income $ 14,745 $ 2,036 + + +See accompanying Notes to Condensed Consolidated Financial Statements. + +4 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Balance Sheets +(In millions) +(Unaudited) + Apr 28, 2024 Jan 28, 2024 +Assets +Current assets: +Cash and cash equivalents $ 7,587 $ 7,280 +Marketable securities 23,851 18,704 +Accounts receivable, net 12,365 9,999 +Inventories 5,864 5,282 +Prepaid expenses and other current assets 4,062 3,080 +Total current assets 53,729 44,345 +Property and equipment, net 4,006 3,914 +Operating lease assets 1,532 1,346 +Goodwill 4,453 4,430 +Intangible assets, net 986 1,112 +Deferred income tax assets 7,798 6,081 +Other assets 4,568 4,500 +Total assets $ 77,072 $ 65,728 +Liabilities and Shareholders' Equity +Current liabilities: +Accounts payable $ 2,715 $ 2,699 +Accrued and other current liabilities 11,258 6,682 +Short-term debt 1,250 1,250 +Total current liabilities 15,223 10,631 +Long-term debt 8,460 8,459 +Long-term operating lease liabilities 1,281 1,119 +Other long-term liabilities 2,966 2,541 +Total liabilities 27,930 22,750 +Commitments and contingencies - see Note 12 +Shareholders’ equity: +Preferred stock — — +Common stock 2 2 +Additional paid-in capital 12,651 13,132 +Accumulated other comprehensive income (loss) (109) 27 +Retained earnings 36,598 29,817 +Total shareholders' equity 49,142 42,978 +Total liabilities and shareholders' equity $ 77,072 $ 65,728 + + +See accompanying Notes to Condensed Consolidated Financial Statements. + +5 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Shareholders' Equity +For the Three Months Ended April 28, 2024 and April 30, 2023 +(Unaudited) +Common Stock +Outstanding Additional Paid-in Capital Accumulated Other Comprehensive Income (Loss) Retained Earnings Total Shareholders' Equity +Shares Amount +(In millions, except per share data) +Balances, Jan 28, 2024 2,464 $ 2 $ 13,132 $ 27 $ 29,817 $ 42,978 +Net income — — — — 14,881 14,881 +Other comprehensive loss — — — (136) — (136) +Issuance of common stock from stock plans 7 — 285 — — 285 +Tax withholding related to vesting of restricted stock units (2) — (1,752) — — (1,752) +Shares repurchased (10) — (33) — (8,002) (8,035) +Cash dividends declared and paid ($0.04 per common share) +— — — — (98) (98) +Stock-based compensation — — 1,019 — — 1,019 +Balances, Apr 28, 2024 2,459 $ 2 $ 12,651 $ (109) $ 36,598 $ 49,142 +Balances, Jan 29, 2023 2,466 $ 2 $ 11,971 $ (43) $ 10,171 $ 22,101 +Net income — — — — 2,043 2,043 +Other comprehensive loss — — — (7) — (7) +Issuance of common stock from stock plans 9 — 246 — — 246 +Tax withholding related to vesting of restricted stock units (2) — (507) — — (507) +Cash dividends declared and paid ($0.04 per common share) +— — — — (99) (99) +Stock-based compensation — — 743 — — 743 +Balances, Apr 30, 2023 2,473 $ 2 $ 12,453 $ (50) $ 12,115 $ 24,520 + +See accompanying Notes to Condensed Consolidated Financial Statements. +6 + +NVIDIA Corporation and Subsidiaries +Condensed Consolidated Statements of Cash Flows +(In millions) +(Unaudited) + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +Cash flows from operating activities: +Net income $ 14,881 $ 2,043 +Adjustments to reconcile net income to net cash provided by operating activities: +Stock-based compensation expense 1,011 735 +Depreciation and amortization 410 384 +Realized and unrealized (gains) losses on investments in non-affiliated entities, net (69) 14 +Deferred income taxes (1,577) (1,135) +Other (145) (34) +Changes in operating assets and liabilities, net of acquisitions: +Accounts receivable (2,366) (252) +Inventories (577) 566 +Prepaid expenses and other assets (726) (215) +Accounts payable (22) 11 +Accrued and other current liabilities 4,202 689 +Other long-term liabilities 323 105 +Net cash provided by operating activities 15,345 2,911 +Cash flows from investing activities: +Proceeds from maturities of marketable securities 4,004 2,512 +Proceeds from sales of marketable securities 149 — +Purchases of marketable securities (9,303) (2,801) +Purchases related to property and equipment and intangible assets (369) (248) +Acquisitions, net of cash acquired (39) (83) +Investments in non-affiliated entities (135) (221) +Net cash used in investing activities (5,693) (841) +Cash flows from financing activities: +Proceeds related to employee stock plans 285 246 +Payments related to repurchases of common stock (7,740) — +Payments related to tax on restricted stock units (1,752) (507) +Dividends paid (98) (99) +Principal payments on property and equipment and intangible assets (40) (20) +Net cash used in financing activities (9,345) (380) +Change in cash and cash equivalents 307 1,690 +Cash and cash equivalents at beginning of period 7,280 3,389 +Cash and cash equivalents at end of period $ 7,587 $ 5,079 + +See accompanying Notes to Condensed Consolidated Financial Statements. +7 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements +(Unaudited) + + +Note 1 - Summary of Significant Accounting Policies +Basis of Presentation +The accompanying unaudited condensed consolidated financial statements were prepared in accordance with accounting principles generally accepted in the United States of America, or U.S. GAAP, for interim financial information and with the instructions to Form 10-Q and Article 10 of Securities and Exchange Commission, or SEC, Regulation S-X. The January 28, 2024 consolidated balance sheet was derived from our audited consolidated financial statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024, as filed with the SEC, but does not include all disclosures required by U.S. GAAP. In the opinion of management, all adjustments, consisting only of normal recurring adjustments considered necessary for a fair statement of results of operations and financial position, have been included. The results for the interim periods presented are not necessarily indicative of the results expected for any future period. The following information should be read in conjunction with the audited consolidated financial statements and notes thereto included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024. +Significant Accounting Policies +There have been no material changes to our significant accounting policies disclosed in Note 1 - Organization and Summary of Significant Accounting Policies, of the Notes to the Consolidated Financial Statements included in our Annual Report on Form 10-K for the fiscal year ended January 28, 2024. +Fiscal Year +We operate on a 52- or 53-week year, ending on the last Sunday in January. Fiscal years 2025 and 2024 are both 52-week years. The first quarters of fiscal years 2025 and 2024 were both 13-week quarters. +Principles of Consolidation +Our condensed consolidated financial statements include the accounts of NVIDIA Corporation and our wholly-owned subsidiaries. All intercompany balances and transactions have been eliminated in consolidation. +Use of Estimates +The preparation of financial statements in conformity with U.S. GAAP requires management to make estimates and assumptions that affect the reported amounts of assets and liabilities and disclosures of contingent assets and liabilities at the date of the financial statements and the reported amounts of revenue and expenses during the reporting period. Actual results could differ materially from our estimates. On an on-going basis, we evaluate our estimates, including those related to revenue recognition, cash equivalents and marketable securities, accounts receivable, inventories and product purchase commitments, income taxes, goodwill, stock-based compensation, litigation, investigation and settlement costs, property, plant, and equipment, and other contingencies. These estimates are based on historical facts and various other assumptions that we believe are reasonable. +Recently Issued Accounting Pronouncements +Recent Accounting Pronouncements Not Yet Adopted +In November 2023, the Financial Accounting Standards Board, or FASB, issued a new accounting standard to provide for additional disclosures about significant expenses in operating segments. The standard is effective for our annual reporting starting with fiscal year 2025 and for interim period reporting starting in fiscal year 2026 retrospectively. We are currently evaluating the impact of this standard on our Consolidated Financial Statements. +In December 2023, the FASB issued a new accounting standard which provides for new and updated income tax disclosures, including disaggregation of rate reconciliation and income taxes paid. The standard is effective for annual periods beginning after December 15, 2024. Early adoption is permitted and should be applied prospectively, with retrospective application permitted. We expect to adopt this standard in our annual reporting starting with fiscal year 2026. We are currently evaluating the impact of this standard on our Consolidated Financial Statements. + + + +8 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 2 - Leases +Our lease obligations primarily consist of operating leases for our headquarters complex, domestic and international office facilities, and data center space, with lease periods expiring between fiscal years 2025 and 2035. +Future minimum lease payments under our non-cancelable operating leases as of April 28, 2024 were as follows: +Operating Lease Obligations + (In millions) +Fiscal Year: +2025 (excluding first quarter of fiscal year 2025) +$ 221 +2026 306 +2027 290 +2028 270 +2029 236 +2030 and thereafter +410 +Total 1,733 +Less imputed interest 206 +Present value of net future minimum lease payments 1,527 +Less short-term operating lease liabilities 246 +Long-term operating lease liabilities $ 1,281 + +In addition, we have operating leases, primarily for our data centers, that are expected to commence during fiscal year 2025 with lease terms of 2 to 11 years for $923 million. +Operating lease expenses were $80 million and $59 million for the first quarter of fiscal years 2025 and 2024, respectively. Short-term and variable lease expenses for the first quarter of fiscal years 2025 and 2024 were not significant. +Other information related to leases was as follows: +Three Months Ended +Apr 28, 2024 Apr 30, 2023 + (In millions) +Supplemental cash flows information +Operating cash flows used for operating leases $ 69 $ 61 +Operating lease assets obtained in exchange for lease obligations 250 106 + +As of April 28, 2024, our operating leases had a weighted average remaining lease term of 6.3 years and a weighted average discount rate of 3.89%. As of January 28, 2024, our operating leases had a weighted average remaining lease term of 6.1 years and a weighted average discount rate of 3.76%. +9 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 3 - Stock-Based Compensation +Our stock-based compensation expense is associated with restricted stock units, or RSUs, performance stock units that are based on our corporate financial performance targets, or PSUs, performance stock units that are based on market conditions, or market-based PSUs, and our employee stock purchase plan, or ESPP. +Our Condensed Consolidated Statements of Income include stock-based compensation expense, net of amounts capitalized into inventory and subsequently recognized to cost of revenue, as follows: + Three Months Ended + Apr 28, 2024 Apr 30, 2023 +(In millions) +Cost of revenue $ 36 $ 27 +Research and development 727 524 +Sales, general and administrative 248 184 +Total $ 1,011 $ 735 + +Equity Award Activity +The following is a summary of our equity award transactions under our equity incentive plans: +RSUs, PSUs, and Market-based PSUs Outstanding + Number of Shares Weighted Average Grant-Date Fair Value Per Share +(In millions, except per share data) +Balances, Jan 28, 2024 37 $ 245.94 +Granted 7 $ 801.79 +Vested (6) $ 176.59 +Balances, Apr 28, 2024 38 $ 361.45 + +As of April 28, 2024, there was $13.2 billion of aggregate unearned stock-based compensation expense. This amount is expected to be recognized over a weighted average period of 2.6 years for RSUs, PSUs, and market-based PSUs, and 0.8 years for ESPP. +Note 4 - Net Income Per Share +The following is a reconciliation of the denominator of the basic and diluted net income per share computations for the periods presented: + Three Months Ended +Apr 28, 2024 Apr 30, 2023 + (In millions, except per share data) +Numerator: +Net income $ 14,881 $ 2,043 +Denominator: +Basic weighted average shares 2,462 2,470 +Dilutive impact of outstanding equity awards 27 20 +Diluted weighted average shares 2,489 2,490 +Net income per share: +Basic (1) $ 6.04 $ 0.83 +Diluted (2) $ 5.98 $ 0.82 +Equity awards excluded from diluted net income per share because their effect would have been anti-dilutive 6 4 + +(1) Calculated as net income divided by basic weighted average shares. +(2) Calculated as net income divided by diluted weighted average shares. +10 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Diluted net income per share is computed using the weighted average number of common and potentially dilutive shares outstanding during the period, using the treasury stock method. Any anti-dilutive effect of equity awards outstanding is not included in the computation of diluted net income per share. +Note 5 - Income Taxes +Income tax expense was $2.4 billion and $166 million for the first quarter of fiscal years 2025 and 2024, respectively. Income tax expense as a percentage of income before income tax was 13.9% and 7.5% for the first quarter of fiscal years 2025 and 2024, respectively. + +The effective tax rate increased primarily due to a decreased effect of tax benefits from the foreign-derived intangible income deduction and stock-based compensation relative to the increase in income before income tax. + +Our effective tax rates for the first quarter of fiscal years 2025 and 2024 were lower than the U.S. federal statutory rate of 21% due to tax benefits from stock-based compensation, the foreign-derived intangible income deduction, income earned in jurisdictions that are subject to taxes lower than the U.S. federal statutory tax rate, and the U.S. federal research tax credit. + +While we believe that we have adequately provided for all uncertain tax positions, or tax positions where we believe it is not more-likely-than-not that the position will be sustained upon review, amounts asserted by tax authorities could be greater or less than our accrued position. Accordingly, our provisions on federal, state and foreign tax related matters to be recorded in the future may change as revised estimates are made or the underlying matters are settled or otherwise resolved with the respective tax authorities. As of April 28, 2024, we do not believe that our estimates, as otherwise provided for, on such tax positions will significantly increase or decrease within the next 12 months. +Note 6 - Cash Equivalents and Marketable Securities +Our cash equivalents and marketable securities related to publicly held debt securities are classified as “available-for-sale” debt securities. +The following is a summary of cash equivalents and marketable securities: + Apr 28, 2024 +Amortized +Cost Unrealized +Gain Unrealized +Loss Estimated +Fair Value Reported as + Cash Equivalents Marketable Securities + (In millions) +Corporate debt securities $ 11,397 $ 3 $ (43) $ 11,357 $ 733 $ 10,624 +Debt securities issued by the U.S. Treasury 11,314 — (62) 11,252 886 10,366 +Money market funds 5,374 — — 5,374 5,374 — +Debt securities issued by U.S. government agencies 2,826 — (7) 2,819 189 2,630 +Certificates of deposit 286 — — 286 69 217 +Foreign government bonds 14 — — 14 — 14 +Total $ 31,211 $ 3 $ (112) $ 31,102 $ 7,251 $ 23,851 + +11 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) + Jan 28, 2024 +Amortized +Cost Unrealized +Gain Unrealized +Loss Estimated +Fair Value Reported as + Cash Equivalents Marketable Securities + (In millions) +Corporate debt securities $ 10,126 $ 31 $ (5) $ 10,152 $ 2,231 $ 7,921 +Debt securities issued by the U.S. Treasury 9,517 17 (10) 9,524 1,315 8,209 +Money market funds 3,031 — — 3,031 3,031 — +Debt securities issued by U.S. government agencies 2,326 8 (1) 2,333 89 2,244 +Certificates of deposit 510 — — 510 294 216 +Foreign government bonds 174 — — 174 60 114 +Total $ 25,684 $ 56 $ (16) $ 25,724 $ 7,020 $ 18,704 + +The following tables provide the breakdown of unrealized losses, aggregated by investment category and length of time that individual securities have been in a continuous loss position: +Apr 28, 2024 + Less than 12 Months 12 Months or Greater Total + Estimated Fair Value Gross Unrealized Loss Estimated Fair Value Gross Unrealized Loss Estimated Fair Value Gross Unrealized Loss + (In millions) +Debt securities issued by the U.S. Treasury $ 9,720 $ (60) $ 756 $ (2) $ 10,476 $ (62) +Corporate debt securities 6,943 (42) 188 (1) 7,131 (43) +Debt securities issued by U.S. government agencies 2,391 (7) — — 2,391 (7) +Total $ 19,054 $ (109) $ 944 $ (3) $ 19,998 $ (112) + +Jan 28, 2024 + Less than 12 Months 12 Months or Greater Total + Estimated Fair Value Gross Unrealized Loss Estimated Fair Value Gross Unrealized Loss Estimated Fair Value Gross Unrealized Loss + (In millions) +Debt securities issued by the U.S. Treasury $ 3,343 $ (5) $ 1,078 $ (5) $ 4,421 $ (10) +Corporate debt securities 1,306 (3) 618 (2) 1,924 (5) +Debt securities issued by U.S. government agencies 670 (1) — — 670 (1) +Total $ 5,319 $ (9) $ 1,696 $ (7) $ 7,015 $ (16) + +The gross unrealized losses are related to fixed income securities, driven primarily by changes in interest rates. Net realized gains and losses were not significant for all periods presented. +12 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +The amortized cost and estimated fair value of cash equivalents and marketable securities are shown below by contractual maturity. +Apr 28, 2024 Jan 28, 2024 +Amortized Cost Estimated Fair Value Amortized Cost Estimated Fair Value +(In millions) +Less than one year $ 16,811 $ 16,800 $ 16,336 $ 16,329 +Due in 1 - 5 years 14,400 14,302 9,348 9,395 +Total $ 31,211 $ 31,102 $ 25,684 $ 25,724 + +Note 7 - Fair Value of Financial Assets and Liabilities and Investments in Non-Affiliated Entities +The fair values of our financial assets and liabilities are determined using quoted market prices of identical assets or quoted market prices of similar assets from active markets. We review fair value hierarchy classification on a quarterly basis. +Pricing Category Fair Value at +Apr 28, 2024 Jan 28, 2024 +(In millions) +Assets +Cash equivalents and marketable securities: +Money market funds Level 1 $ 5,374 $ 3,031 +Corporate debt securities Level 2 $ 11,357 $ 10,152 +Debt securities issued by the U.S. Treasury Level 2 $ 11,252 $ 9,524 +Debt securities issued by U.S. government agencies Level 2 $ 2,819 $ 2,333 +Certificates of deposit Level 2 $ 286 $ 510 +Foreign government bonds Level 2 $ 14 $ 174 +Other assets (Investments in non-affiliated entities): +Publicly-held equity securities Level 1 $ 287 $ 225 +Liabilities (1) +0.584% Notes Due 2024 +Level 2 $ 1,242 $ 1,228 +3.20% Notes Due 2026 +Level 2 $ 960 $ 970 +1.55% Notes Due 2028 +Level 2 $ 1,096 $ 1,115 +2.85% Notes Due 2030 +Level 2 $ 1,331 $ 1,367 +2.00% Notes Due 2031 +Level 2 $ 1,026 $ 1,057 +3.50% Notes Due 2040 +Level 2 $ 805 $ 851 +3.50% Notes Due 2050 +Level 2 $ 1,487 $ 1,604 +3.70% Notes Due 2060 +Level 2 $ 368 $ 403 + + +(1) These liabilities are carried on our Condensed Consolidated Balance Sheets at their original issuance value, net of unamortized debt discount and issuance costs. +Investments in Non-Affiliated Entities +Our investments in non-affiliated entities include marketable equity securities, which are publicly traded, and non-marketable equity securities, which are primarily investments in privately held companies. +Our marketable equity securities have readily determinable fair values and are recorded in long-term other assets on our Condensed Consolidated Balance Sheets at fair value with changes in fair value recorded in Other income and expense, net on our Condensed Consolidated Statements of Income. Marketable equity securities totaled $287 million and $225 million as of April 28, 2024 and January 28, 2024, respectively. The net unrealized and realized gains and losses of investments in marketable securities were not significant for the first quarter of fiscal years 2025 and 2024. +13 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Our non-marketable equity securities are recorded in long-term other assets on our Condensed Consolidated Balance Sheets and valued under the measurement alternative. The carrying value of our non-marketable equity securities totaled $1.5 billion and $1.3 billion as of April 28, 2024 and January 28, 2024, respectively. Gains and losses on these investments, realized and unrealized, are recognized in Other income and expense, net on our Condensed Consolidated Statements of Income. + +(1) During the first quarter of fiscal years 2025 and 2024, we recorded an inventory provision of $210 million and $105 million, respectively, in cost of revenue. + + Apr 28, 2024 Jan 28, 2024 +Other Assets: (In millions) +Prepaid supply and capacity agreements (1) $ 2,232 $ 2,458 +Investments in non-affiliated entities 1,750 1,546 +Prepaid royalties 358 364 +Other 228 132 + +We recognized $188 million in revenue in the first quarter of fiscal year 2025 from deferred revenue as of January 28, 2024. +Revenue allocated to remaining performance obligations, which includes deferred revenue and amounts that will be invoiced and recognized as revenue in future periods, was $1.3 billion as of April 28, 2024. We expect to recognize approximately 38% of this revenue over the next twelve months and the remainder thereafter. This excludes revenue related to performance obligations for contracts with a length of one year or less. +16 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 10 - Derivative Financial Instruments +We enter into foreign currency forward contracts to mitigate the impact of foreign currency exchange rate movements on our operating expenses. These contracts are designated as cash flow hedges for hedge accounting treatment. Gains or losses on the contracts are recorded in accumulated other comprehensive income or loss and reclassified to operating expense when the related operating expenses are recognized in earnings or ineffectiveness should occur. +We also enter into foreign currency forward contracts to mitigate the impact of foreign currency movements on monetary assets and liabilities. The change in fair value of these non-designated contracts is recorded in other income or expense and offsets the change in fair value of the hedged foreign currency denominated monetary assets and liabilities, which is also recorded in other income or expense. +The table below presents the notional value of our foreign currency contracts outstanding: + Apr 28, 2024 Jan 28, 2024 +(In millions) +Designated as cash flow hedges $ 1,198 $ 1,168 +Non-designated hedges $ 704 $ 597 + +The unrealized gains and losses or fair value of our foreign currency contracts was not significant as of April 28, 2024 and January 28, 2024. +As of April 28, 2024, all designated foreign currency contracts mature within 18 months. The expected realized gains and losses deferred to accumulated other comprehensive income or loss related to foreign currency contracts was not significant. +During the first quarter of fiscal years 2025 and 2024, the impact of derivative financial instruments designated for hedge accounting treatment in other comprehensive income or loss was not significant and the instruments were determined to be highly effective. +Note 11 - Debt +Long-Term Debt +Expected +Remaining Term (years) Effective +Interest Rate Carrying Value at +Apr 28, 2024 Jan 28, 2024 +(In millions) +0.584% Notes Due 2024 +0.1 0.66% 1,250 1,250 +3.20% Notes Due 2026 +2.4 3.31% 1,000 1,000 +1.55% Notes Due 2028 +4.1 1.64% 1,250 1,250 +2.85% Notes Due 2030 +5.9 2.93% 1,500 1,500 +2.00% Notes Due 2031 +7.1 2.09% 1,250 1,250 +3.50% Notes Due 2040 +15.9 3.54% 1,000 1,000 +3.50% Notes Due 2050 +25.9 3.54% 2,000 2,000 +3.70% Notes Due 2060 +36.0 3.73% 500 500 +Unamortized debt discount and issuance costs (40) (41) +Net carrying amount 9,710 9,709 +Less short-term portion (1,250) (1,250) +Total long-term portion $ 8,460 $ 8,459 + +Our notes are unsecured senior obligations. Existing and future liabilities of our subsidiaries will be effectively senior to the notes. Our notes pay interest semi-annually. We may redeem each of our notes prior to maturity, as defined in the applicable form of note. The maturity of the notes are calendar year. +As of April 28, 2024, we were in compliance with the required covenants, which are non-financial in nature, under the outstanding notes. +17 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Commercial Paper +We have a $575 million commercial paper program to support general corporate purposes. As of April 28, 2024, we had no commercial paper outstanding. +Note 12 - Commitments and Contingencies +Purchase Obligations +Our purchase obligations reflect our commitment to purchase components used to manufacture our products, including long-term supply and capacity agreements, certain software and technology licenses, other goods and services and long-lived assets. +As of April 28, 2024, we had outstanding inventory purchases and long-term supply and capacity obligations totaling $18.8 billion. We enter into agreements with contract manufacturers that allow them to procure inventory based upon our defined criteria, and in certain instances, these agreements are cancellable, able to be rescheduled, and adjustable for our business needs prior to placing firm orders. These changes may result in costs incurred through the date of cancellation. Other non-inventory purchase obligations were $10.6 billion, including $8.8 billion of multi-year cloud service agreements. We expect our cloud service agreements to be used to support our research and development efforts and our DGX Cloud offerings. +Total future purchase commitments as of April 28, 2024 are as follows: +Commitments + (In millions) +Fiscal Year: +2025 (excluding first quarter of fiscal year 2025) +$ 19,306 +2026 3,438 +2027 2,573 +2028 2,222 +2029 1,585 +2030 and thereafter +249 +Total $ 29,373 + +In addition to the purchase commitments included in the table above, at the end of the first quarter of fiscal year 2025, we had commitments of approximately $1.2 billion to complete business combinations, subject to closing conditions, and acquire land and buildings. +Accrual for Product Warranty Liabilities +The estimated amount of product warranty liabilities was $532 million and $306 million as of April 28, 2024 and January 28, 2024, respectively. The estimated product returns and product warranty activity consisted of the following: +Three Months Ended +Apr 28, 2024 Apr 30, 2023 +(In millions) +Balance at beginning of period $ 306 $ 82 +Additions 234 13 +Utilization (8) (18) +Balance at end of period $ 532 $ 77 + +We have provided indemnities for matters such as tax, product, and employee liabilities. We have included intellectual property indemnification provisions in our technology-related agreements with third parties. Maximum potential future payments cannot be estimated because many of these agreements do not have a maximum stated liability. We have not recorded any liability in our Condensed Consolidated Financial Statements for such indemnifications. +18 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Litigation +Securities Class Action and Derivative Lawsuits +The plaintiffs in the putative securities class action lawsuit, captioned 4:18-cv-07669-HSG, initially filed on December 21, 2018 in the United States District Court for the Northern District of California, and titled In Re NVIDIA Corporation Securities Litigation, filed an amended complaint on May 13, 2020. The amended complaint asserted that NVIDIA and certain NVIDIA executives violated Section 10(b) of the Securities Exchange Act of 1934, as amended, or the Exchange Act, and SEC Rule 10b-5, by making materially false or misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand between May 10, 2017 and November 14, 2018. Plaintiffs also alleged that the NVIDIA executives who they named as defendants violated Section 20(a) of the Exchange Act. Plaintiffs sought class certification, an award of unspecified compensatory damages, an award of reasonable costs and expenses, including attorneys’ fees and expert fees, and further relief as the Court may deem just and proper. On March 2, 2021, the district court granted NVIDIA’s motion to dismiss the complaint without leave to amend, entered judgment in favor of NVIDIA and closed the case. On March 30, 2021, plaintiffs filed an appeal from judgment in the United States Court of Appeals for the Ninth Circuit, case number 21-15604. On August 25, 2023, a majority of a three-judge Ninth Circuit panel affirmed in part and reversed in part the district court’s dismissal of the case, with a third judge dissenting on the basis that the district court did not err in dismissing the case. On November 15, 2023, the Ninth Circuit denied NVIDIA’s petition for rehearing en banc of the Ninth Circuit panel’s majority decision to reverse in part the dismissal of the case, which NVIDIA had filed on October 10, 2023. On November 21, 2023, NVIDIA filed a motion with the Ninth Circuit for a stay of the mandate pending NVIDIA’s petition for a writ of certiorari in the Supreme Court of the United States and the Supreme Court’s resolution of the matter. On December 5, 2023, the Ninth Circuit granted NVIDIA’s motion to stay the mandate. NVIDIA filed a petition for a writ of certiorari on March 4, 2024. Four amicus briefs in support of NVIDIA’s petition were filed on April 5, 2024. +The putative derivative lawsuit pending in the United States District Court for the Northern District of California, captioned 4:19-cv-00341-HSG, initially filed January 18, 2019 and titled In re NVIDIA Corporation Consolidated Derivative Litigation, was stayed pending resolution of the plaintiffs’ appeal in the In Re NVIDIA Corporation Securities Litigation action. On February 22, 2022, the court administratively closed the case, but stated that it would reopen the case once the appeal in the In Re NVIDIA Corporation Securities Litigation action is resolved. The stay remains in place. The lawsuit asserts claims, purportedly on behalf of us, against certain officers and directors of the Company for breach of fiduciary duty, unjust enrichment, waste of corporate assets, and violations of Sections 14(a), 10(b), and 20(a) of the Exchange Act based on the dissemination of allegedly false and misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand. The plaintiffs are seeking unspecified damages and other relief, including reforms and improvements to NVIDIA’s corporate governance and internal procedures. +The putative derivative actions initially filed September 24, 2019 and pending in the United States District Court for the District of Delaware, Lipchitz v. Huang, et al. (Case No. 1:19-cv-01795-UNA) and Nelson v. Huang, et. al. (Case No. 1:19-cv-01798- UNA), remain stayed pending resolution of the plaintiffs’ appeal in the In Re NVIDIA Corporation Securities Litigation action. The lawsuits assert claims, purportedly on behalf of us, against certain officers and directors of the Company for breach of fiduciary duty, unjust enrichment, insider trading, misappropriation of information, corporate waste and violations of Sections 14(a), 10(b), and 20(a) of the Exchange Act based on the dissemination of allegedly false, and misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand. The plaintiffs seek unspecified damages and other relief, including disgorgement of profits from the sale of NVIDIA stock and unspecified corporate governance measures. +Another putative derivative action was filed on October 30, 2023 in the Court of Chancery of the State of Delaware, captioned Horanic v. Huang, et al. (Case No. 2023-1096-KSJM). This lawsuit asserts claims, purportedly on behalf of us, against certain officers and directors of the Company for breach of fiduciary duty and insider trading based on the dissemination of allegedly false and misleading statements related to channel inventory and the impact of cryptocurrency mining on GPU demand. The plaintiffs seek unspecified damages and other relief, including disgorgement of profits from the sale of NVIDIA stock and reform of unspecified corporate governance measures. This derivative matter is stayed pending the final resolution of In Re NVIDIA Corporation Securities Litigation action. +Accounting for Loss Contingencies +As of April 28, 2024, there are no accrued contingent liabilities associated with the legal proceedings described above based on our belief that liabilities, while possible, are not probable. Further, except as described above, any possible loss or range of loss in these matters cannot be reasonably estimated at this time. We are engaged in legal actions not described above arising in the ordinary course of business and, while there can be no assurance of favorable outcomes, we believe that the ultimate outcome of these actions will not have a material adverse effect on our operating results, liquidity or financial position. +19 +NVIDIA Corporation and Subsidiaries +Notes to Condensed Consolidated Financial Statements (Continued) +(Unaudited) +Note 13 - Shareholders’ Equity +Capital Return Program +During the first quarter of fiscal year 2025, we repurchased 9.9 million shares of our common stock for $8.0 billion. We did not repurchase any shares during the first quarter of fiscal year 2024. As of April 28, 2024, we were authorized, subject to certain specifications, to repurchase up to $14.5 billion additional shares of our common stock. Our share repurchase program aims to offset dilution from shares issued to employees. We may pursue additional share repurchases as we weigh market factors and other investment opportunities. +From April 29, 2024 through May 24, 2024, we repurchased 2.3 million shares for $2.1 billion pursuant to a Rule 10b5-1 trading plan. +During the first quarter of fiscal years 2025 and 2024, we paid $98 million and $99 million in cash dividends to our shareholders, respectively. Our cash dividend program and the payment of future cash dividends under that program are subject to our Board of Directors' continuing determination that the dividend program and the declaration of dividends thereunder are in the best interests of our shareholders. +Note 14 - Segment Information +Our Chief Executive Officer is our chief operating decision maker, or CODM, and reviews financial information presented on an operating segment basis for purposes of making decisions and assessing financial performance. +The Compute & Networking segment includes our Data Center accelerated computing platform; networking; automotive artificial intelligence, or AI, Cockpit, autonomous driving development agreements, and autonomous vehicle solutions; electric vehicle computing platforms; Jetson for robotics and other embedded platforms; NVIDIA AI Enterprise and other software; and DGX Cloud. +The Graphics segment includes GeForce GPUs for gaming and PCs, the GeForce NOW game streaming service and related infrastructure, and solutions for gaming platforms; Quadro/NVIDIA RTX GPUs for enterprise workstation graphics; virtual GPU software for cloud-based visual and virtual computing; automotive platforms for infotainment systems; and Omniverse Enterprise software for building and operating 3D internet applications. +Operating results by segment include costs or expenses directly attributable to each segment, and costs or expenses that are leveraged across our unified architecture and therefore allocated between our two segments. +The “All Other” category includes the expenses that our CODM does not assign to either Compute & Networking or Graphics for purposes of making operating decisions or assessing financial performance. The expenses include stock-based compensation expense, corporate infrastructure and support costs, acquisition-related and other costs, and other non-recurring charges and benefits that our CODM deems to be enterprise in nature. +Our CODM does not review any information regarding total assets on a reportable segment basis. Depreciation and amortization expenses directly attributable to each reportable segment are included in operating results for each segment. However, our CODM does not evaluate depreciation and amortization expense by operating segment and, therefore, it is not separately presented. The accounting policies for segment reporting are the same as for our consolidated financial statements. The table below presents details of our reportable segments and the “All Other” category. + Compute & Networking Graphics All Other Consolidated + (In millions) +Three Months Ended Apr 28, 2024 + +Revenue $ 22,675 $ 3,369 $ — $ 26,044 +Operating income (loss) $ 17,047 $ 1,241 $ (1,379) $ 16,909 +Three Months Ended Apr 30, 2023 + +Revenue $ 4,460 $ 2,732 $ — $ 7,192 +Operating income (loss) $ 2,160 $ 1,046 $ (1,066) $ 2,140 + + + +""" + +# Add + + +def cost_reduction_analyst(): + return """ + + You are a Cost Reduction Analyst. + Your task is to thoroughly analyze NVIDIA's SEC 10-K filings to identify areas where the company can reduce expenditures. Focus on evaluating operating expenses, administrative costs, research and development (R&D) expenditures, and capital expenditures. Look for patterns of excessive spending, inefficiencies, and opportunities for cost savings. Provide a detailed report outlining specific areas where costs can be cut and suggest practical measures for achieving these reductions. + + When finished make a call to the phone number provided and summarize your findings to the person on the other end of the line. + + """ + + +def revenue_maximalist_analyst(): + return """ + + You are a Revenue Maximization Analyst. + Your task is to examine NVIDIA's SEC 10-K filings to identify opportunities to maximize revenues. Analyze revenue streams from different product lines, geographical markets, and customer segments. Look for underperforming areas, untapped markets, and potential for price adjustments. Provide a comprehensive report on strategies to increase revenues, such as expanding product offerings, entering new markets, or optimizing pricing strategies. + + + """ + + +def operational_efficiency(): + return """ + You are an Operational Efficiency and Cost Control Specialist. + Your task is to review NVIDIA's SEC 10-K filings to evaluate the company's operational efficiency and identify opportunities for cost control. Focus on areas such as supply chain management, manufacturing processes, and inventory management. Look for inefficiencies, bottlenecks, and areas where costs can be controlled without compromising quality. Provide a detailed analysis and recommendations for improving operational efficiency and reducing costs. + + + + """ + + +def strategic_investment_analyst(): + return """ + + You are a Strategic Investment Analyst. + Your task is to analyze NVIDIA's SEC 10-K filings to evaluate the company's investment strategies and identify areas where expenditures can be optimized. Focus on R&D investments, capital projects, and acquisition strategies. Assess the return on investment (ROI) for significant expenditures and identify any investments that are not yielding expected returns. Provide a detailed report on how NVIDIA can reallocate or reduce investments to maximize financial performance. + + + """ + + +def sales_marketing_agent_prompt(): + return """ + You are a Sales and Marketing Optimization Specialist. Your task is to examine NVIDIA's SEC 10-K filings to evaluate the effectiveness of the company's sales and marketing efforts and identify areas where expenditures can be reduced while maximizing revenue. Analyze marketing expenses, sales strategies, and customer acquisition costs. Look for areas where spending can be optimized and suggest strategies for increasing marketing efficiency and sales effectiveness. Provide a comprehensive report with actionable recommendations. + + These prompts will help each agent focus on specific aspects of NVIDIA's expenditures and revenue opportunities, ensuring a thorough analysis aimed at cutting costs and maximizing revenues. + + """ + + +def call_with_summary(summary: str = None): + """ + Calls the Bland API with a summary of the given task. + + Args: + task (str): The task to be summarized. + + Returns: + str: The response text from the API call. + """ + url = "https://api.bland.ai/v1/calls" + authorization = os.getenv("BLAND_API_KEY") + data = { + "phone_number": "+17866955339", + "task": f"You're the nvidia SEC summary agent, here is a summary of growth{summary}", + "voice_id": 123, + } + + headers = { + "Content-Type": "application/json", + "Authorization": authorization, + } + + response = requests.post(url, headers=headers, data=json.dumps(data)) + + print(response.text) + + return response.text + + +# Initialize the director agent +cost_reduction_agent = Agent( + agent_name="Cost Reduction Analyst", + system_prompt=cost_reduction_analyst(), + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="cost_reduction_analyst.json", + # tools = [call_with_summary], +) + +# Initialize the agents +revenue_maximalist_agent = Agent( + agent_name="Revenue Maximization Analyst", + system_prompt=revenue_maximalist_analyst(), + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="revenue_maximalist_analyst.json", + # agent_ops_on=True, + # # long_term_memory=memory, + # context_length=10000, +) + +cost_control_agent = Agent( + agent_name="Operational Efficiency and Cost Control Specialist", + system_prompt=operational_efficiency(), + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="operational_efficiency.json", + # agent_ops_on=True, + # # long_term_memory=memory, +) + +investment_analyst_agent = Agent( + agent_name="Strategic Investment Analyst", + system_prompt=strategic_investment_analyst(), + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="strategic_investment_analyst.json", + # agent_ops_on=True, + # # long_term_memory=memory, +) + +sales_marketing_agent = Agent( + agent_name="Sales and Marketing Optimization Specialist", + system_prompt=sales_marketing_agent_prompt(), + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + saved_state_path="sales_marketing_agent.json", + # agent_ops_on=True, + # # long_term_memory=memory, + # context_length=8192, +) + + +final_agent = Agent( + agent_name="Final Agent", + system_prompt="You are the final agent. Please summarize the findings of the previous agents and provide a comprehensive report on how NVIDIA can optimize its financial performance. When finished make a call to the phone number provided and summarize your findings to the person on the other end of the line. Summarize the points such as how to lower the costs and increase the revenue.", + llm=llm, + max_loops=1, + dashboard=False, + state_save_file_type="json", + tools=[call_with_summary], +) + + +agents = [ + cost_reduction_agent, + revenue_maximalist_agent, + cost_control_agent, + investment_analyst_agent, + sales_marketing_agent, +] + + +# Swarm +swarm = MixtureOfAgents( + name="Mixture of Accountants", + agents=agents, + layers=1, + final_agent=final_agent, +) + + +# Run the swarm +out = swarm.run( + f"Analyze the following Nvidia financial data and locate unnecessary expenditures: {SEC_FILLING}" +) +print(out) diff --git a/playground/structs/search_arena/requirements.txt b/playground/structs/search_arena/requirements.txt new file mode 100644 index 00000000..4e472e75 --- /dev/null +++ b/playground/structs/search_arena/requirements.txt @@ -0,0 +1,3 @@ +swarms +exa_py +tavily-python \ No newline at end of file diff --git a/playground/structs/search_arena/search_agents.py b/playground/structs/search_arena/search_agents.py new file mode 100644 index 00000000..4b8363a2 --- /dev/null +++ b/playground/structs/search_arena/search_agents.py @@ -0,0 +1,339 @@ +import os +from typing import Any, Dict + +import requests +import tavily +from dotenv import load_dotenv + +from swarms import Agent, OpenAIChat +from swarms.tools.prebuilt.bing_api import fetch_web_articles_bing_api +from swarms.utils.loguru_logger import logger + +load_dotenv() + +try: + from openai import OpenAI + + from swarms import BaseLLM +except ImportError as e: + raise ImportError(f"Required modules are not available: {e}") + + +def perplexity_api_key(): + try: + api_key = os.getenv("PPLX_API_KEY") + return api_key + except Exception as e: + print(f"Error: {e}") + + +class Perplexity(BaseLLM): + """ + A class to interact with the Perplexity API using OpenAI's interface. + """ + + def __init__( + self, api_key: str = perplexity_api_key(), *args, **kwargs + ): + """ + Initialize the Perplexity class with an API key. + + Args: + api_key (str): The API key for authenticating with the OpenAI client. + """ + super().__init__(*args, **kwargs) + self.client = OpenAI( + api_key=api_key, + base_url="https://api.perplexity.ai", + *args, + **kwargs, + ) + + def run(self, task: str, *args, **kwargs): + """ + Run the model to process the given task. + + Args: + task (str): The task to be performed. + + Returns: + dict: The processed output from the model. + """ + messages = [ + { + "role": "system", + "content": ( + "You are an artificial intelligence assistant and you need to " + "engage in a helpful, detailed, polite conversation with a user." + ), + }, + { + "role": "user", + "content": task, + }, + ] + try: + response = self.client.chat.completions.create( + model="llama-3-sonar-large-32k-online", + messages=messages, + ) + return response + except Exception as e: + raise RuntimeError(f"Error running the model: {e}") + + +def check_exa_api(): + try: + api_key = os.getenv("EXA_API_KEY") + return api_key + except Exception as e: + print(f"Error: {e}") + + +class ExaAgent(BaseLLM): + """ + A class to interact with the Exa API. + """ + + def __init__(self, api_key: str = check_exa_api(), *args, **kwargs): + """ + Initialize the ExaAgent class with an API key. + + Args: + api_key (str): The API key for authenticating with the Exa client. + """ + super().__init__(*args, **kwargs) + try: + from exa_py import Exa + + self.exa = Exa(api_key=api_key) + except ImportError as e: + raise ImportError(f"Failed to import Exa: {e}") + + def run(self, task: str, *args, **kwargs): + """ + Run a search query using the Exa API. + + Args: + task (str): The search query. + + Returns: + dict: The search results from the Exa API. + """ + try: + results = self.exa.search( + task, use_autoprompt=True, *args, **kwargs + ) + return results + except Exception as e: + raise RuntimeError(f"Error running the search query: {e}") + + +class ResearchAgent: + """ + A class to represent a research agent that uses an LLM to summarize content from various sources. + """ + + def __init__( + self, + api_key: str = None, + output_dir: str = "research_base", + n_results: int = 2, + temperature: float = 0.2, + max_tokens: int = 3500, + ): + """ + Initialize the ResearchAgent class with necessary parameters. + + Args: + api_key (str): The API key for the Bing API. + output_dir (str): The directory for storing memory outputs. Default is "research_base". + n_results (int): Number of results to return from the memory. Default is 2. + temperature (float): The temperature setting for the LLM. Default is 0.2. + max_tokens (int): The maximum number of tokens for the LLM. Default is 3500. + """ + self.api_key = api_key + + self.llm = OpenAIChat( + temperature=temperature, max_tokens=max_tokens + ) + self.agent = self._initialize_agent() + + def _initialize_agent(self): + """ + Initialize the agent with the provided parameters and system prompt. + + Returns: + Agent: An initialized Agent instance. + """ + research_system_prompt = """ + Research Agent LLM Prompt: Summarizing Sources and Content + Objective: Your task is to summarize the provided sources and the content within those sources. The goal is to create concise, accurate, and informative summaries that capture the key points of the original content. + Instructions: + 1. Identify Key Information: ... + 2. Summarize Clearly and Concisely: ... + 3. Preserve Original Meaning: ... + 4. Include Relevant Details: ... + 5. Structure: ... + """ + + return Agent( + agent_name="Research Agent", + system_prompt=research_system_prompt, + llm=self.llm, + max_loops=1, + autosave=True, + dashboard=False, + # tools=[fetch_web_articles_bing_api], + verbose=True, + ) + + def run(self, task: str, *args, **kwargs): + """ + Run the research agent to fetch and summarize web articles related to the task. + + Args: + task (str): The task or query for the agent to process. + + Returns: + str: The agent's response after processing the task. + """ + articles = fetch_web_articles_bing_api(task) + sources_prompts = "".join([task, articles]) + agent_response = self.agent.run(sources_prompts) + return agent_response + + +def check_tavily_api(): + try: + api_key = os.getenv("TAVILY_API_KEY") + return api_key + except Exception as e: + print(f"Error: {e}") + + +class TavilyWrapper: + """ + A wrapper class for the Tavily API to facilitate searches and retrieve relevant information. + """ + + def __init__(self, api_key: str = check_tavily_api()): + """ + Initialize the TavilyWrapper with the provided API key. + + Args: + api_key (str): The API key for authenticating with the Tavily API. + """ + if not isinstance(api_key, str): + raise TypeError("API key must be a string") + + self.api_key = api_key + self.client = self._initialize_client(api_key) + + def _initialize_client(self, api_key: str) -> Any: + """ + Initialize the Tavily client with the provided API key. + + Args: + api_key (str): The API key for authenticating with the Tavily API. + + Returns: + TavilyClient: An initialized Tavily client instance. + """ + try: + return tavily.TavilyClient(api_key=api_key) + except Exception as e: + raise RuntimeError(f"Error initializing Tavily client: {e}") + + def run(self, task: str) -> Dict[str, Any]: + """ + Perform a search query using the Tavily API. + + Args: + task (str): The search query. + + Returns: + dict: The search results from the Tavily API. + """ + if not isinstance(task, str): + raise TypeError("Task must be a string") + + try: + response = self.client.search( + query=task, search_depth="advanced" + ) + return response + except Exception as e: + raise RuntimeError(f"Error performing search: {e}") + + +def you_search_api_key(): + try: + api_key = os.getenv("YOU_API_KEY") + return api_key + except Exception as e: + print(f"Error: {e}") + + +class YouSearchAgent: + """ + A wrapper class for the YDC Index API to facilitate fetching AI snippets based on a query. + """ + + def __init__(self, api_key: str = you_search_api_key()): + """ + Initialize the AISnippetsWrapper with the provided API key. + + Args: + api_key (str): The API key for authenticating with the YDC Index API. + """ + + self.api_key = api_key + + def run(self, task: str) -> Dict[str, Any]: + """ + Fetch AI snippets for the given query using the YDC Index API. + + Args: + task (str): The search query. + + Returns: + dict: The search results from the YDC Index API. + """ + if not isinstance(task, str): + raise TypeError("Task must be a string") + + headers = { + "X-API-Key": os.getenv("YOU_API_KEY") + } + params = {"query": task} + + try: + response = requests.get( + f"https://api.ydc-index.io/rag?query={task}", + params=params, + headers=headers, + ) + return response.json() + except requests.RequestException as e: + raise RuntimeError(f"Error fetching AI snippets: {e}") + + +# task = "What is the swarmms framework" + +# # Run all of the agents +# agents = [ +# Perplexity, +# ExaAgent, +# # ResearchAgent, +# TavilyWrapper, +# # YouSearchAgent, +# # Brave +# ] + +# # Run each agent with the given task +# for agent_class in agents: +# logger.info(f"Running agent: {agent_class.__name__}") +# agent = agent_class() +# response = agent.run(task) +# print(response) diff --git a/scripts/cleanup/json_log_cleanup.py b/scripts/cleanup/json_log_cleanup.py index 8e3ee53a..e7831095 100644 --- a/scripts/cleanup/json_log_cleanup.py +++ b/scripts/cleanup/json_log_cleanup.py @@ -31,4 +31,4 @@ def cleanup_json_logs(name: str = None): # Call the function -cleanup_json_logs("artifacts_three") +cleanup_json_logs("artifacts_five") diff --git a/swarms/models/popular_llms.py b/swarms/models/popular_llms.py index abf7df11..4c80caec 100644 --- a/swarms/models/popular_llms.py +++ b/swarms/models/popular_llms.py @@ -10,6 +10,7 @@ from langchain.llms.mosaicml import MosaicML from langchain.llms.openai import OpenAI # , OpenAIChat, AzureOpenAI from langchain_community.llms.octoai_endpoint import OctoAIEndpoint from langchain.llms.replicate import Replicate +from langchain_community.llms.fireworks import Fireworks # noqa: F401 class Anthropic(Anthropic): diff --git a/swarms/structs/agent.py b/swarms/structs/agent.py index 30fee9a9..20c467b6 100644 --- a/swarms/structs/agent.py +++ b/swarms/structs/agent.py @@ -513,6 +513,9 @@ class Agent(BaseStructure): "Could not import agentops, try installing agentops: $ pip3 install agentops" ) + # Check the parameters + self.check_parameters() + def set_system_prompt(self, system_prompt: str): """Set the system prompt""" self.system_prompt = system_prompt @@ -720,6 +723,19 @@ class Agent(BaseStructure): for letter in content: print(letter, end="") + def check_parameters(self): + if self.llm is None: + raise ValueError("Language model is not provided") + + if self.system_prompt is None: + raise ValueError("System prompt is not provided") + + if self.max_loops is None: + raise ValueError("Max loops is not provided") + + if self.agent_name is None: + raise ValueError("Agent name is not provided") + ########################## FUNCTION CALLING ########################## def run( @@ -781,6 +797,14 @@ class Agent(BaseStructure): ) else: + + if exists(self.tokenizer): + task_prompt = ( + self.count_and_shorten_context_window( + task_prompt + ) + ) + response_args = ( (task_prompt, *args) if img is None @@ -789,7 +813,10 @@ class Agent(BaseStructure): response = self.llm(*response_args, **kwargs) # Print - print(response) + if self.streaming_on is True: + response = self.stream_response(response) + else: + print(response) # Add the response to the memory self.short_memory.add( @@ -826,27 +853,7 @@ class Agent(BaseStructure): # Sentiment analysis if self.sentiment_analyzer: - sentiment = self.sentiment_analyzer(response) - print(f"Sentiment: {sentiment}") - - if sentiment > self.sentiment_threshold: - print( - f"Sentiment: {sentiment} is above" - " threshold:" - f" {self.sentiment_threshold}" - ) - elif sentiment < self.sentiment_threshold: - print( - f"Sentiment: {sentiment} is below" - " threshold:" - f" {self.sentiment_threshold}" - ) - - # print(f"Sentiment: {sentiment}") - self.short_memory.add( - role=self.agent_name, - content=sentiment, - ) + self.sentiment_analysis_handler(response) # print(response) @@ -920,9 +927,15 @@ class Agent(BaseStructure): if self.agent_ops_on is True: self.check_end_session_agentops() - return response + if self.return_history: + return self.short_memory.return_history_as_string() + else: + return response + except Exception as error: - print(f"Error running agent: {error}") + logger.info( + f"Error running agent: {error} optimize your input parameters" + ) raise error def __call__(self, task: str = None, img: str = None, *args, **kwargs): @@ -984,12 +997,11 @@ class Agent(BaseStructure): # Query the long term memory database ltr = self.long_term_memory.query(query, *args, **kwargs) - ltr = str(ltr) + # ltr = str(ltr) # Retrieve only the chunk size of the memory + logger.info(f"Chunking to {self.memory_chunk_size}") ltr = retrieve_tokens(ltr, self.memory_chunk_size) - - # print(f"Long Term Memory Query: {ltr}") return ltr def add_memory(self, message: str): @@ -1690,3 +1702,122 @@ class Agent(BaseStructure): f"Error detected: {error} make sure you have inputted a callable and that it has documentation as docstrings" ) raise error + + def memory_query(self, task: str = None, *args, **kwargs): + try: + if self.long_term_memory is not None: + memory_retrieval = self.long_term_memory_prompt( + task, *args, **kwargs + ) + # print(len(memory_retrieval)) + + # Merge the task prompt with the memory retrieval + task_prompt = ( + f"{task} Documents Available: {memory_retrieval}" + ) + + response = self.llm(task_prompt, *args, **kwargs) + print(response) + + self.short_memory.add( + role=self.agent_name, content=response + ) + return response + except Exception as e: + print(f"An error occurred: {e}") + return None + + def sentiment_analysis_handler(self, response: str = None): + try: + # Sentiment analysis + if self.sentiment_analyzer: + sentiment = self.sentiment_analyzer(response) + print(f"Sentiment: {sentiment}") + + if sentiment > self.sentiment_threshold: + print( + f"Sentiment: {sentiment} is above" + " threshold:" + f" {self.sentiment_threshold}" + ) + elif sentiment < self.sentiment_threshold: + print( + f"Sentiment: {sentiment} is below" + " threshold:" + f" {self.sentiment_threshold}" + ) + + # print(f"Sentiment: {sentiment}") + self.short_memory.add( + role=self.agent_name, + content=sentiment, + ) + except Exception as e: + print(f"Error occurred during sentiment analysis: {e}") + + def count_and_shorten_context_window( + self, history: str, *args, **kwargs + ): + """ + Count the number of tokens in the context window and shorten it if it exceeds the limit. + + Args: + history (str): The history of the conversation. + + Returns: + str: The shortened context window. + """ + # Count the number of tokens in the context window + count = self.tokenizer.count_tokens(history) + + # Shorten the context window if it exceeds the limit, keeping the last n tokens, need to implement the indexing + if count > self.context_length: + history = history[-self.context_length :] + + return history + + def output_cleaner_and_output_type( + self, response: str, *args, **kwargs + ): + # Apply the cleaner function to the response + if self.output_cleaner is not None: + logger.info("Applying output cleaner to response.") + response = self.output_cleaner(response) + logger.info(f"Response after output cleaner: {response}") + + # Prepare the output for the output model + if self.output_type is not None: + # logger.info("Preparing output for output model.") + response = prepare_output_for_output_model(response) + print(f"Response after output model: {response}") + + return response + + def stream_response(self, response: str, delay: float = 0.1) -> None: + """ + Streams the response token by token. + + Args: + response (str): The response text to be streamed. + delay (float, optional): Delay in seconds between printing each token. Default is 0.1 seconds. + + Raises: + ValueError: If the response is not provided. + Exception: For any errors encountered during the streaming process. + + Example: + response = "This is a sample response from the API." + stream_response(response) + """ + # Check for required inputs + if not response: + raise ValueError("Response is required.") + + try: + # Stream and print the response token by token + for token in response.split(): + print(token, end=" ", flush=True) + time.sleep(delay) + print() # Ensure a newline after streaming + except Exception as e: + print(f"An error occurred during streaming: {e}") diff --git a/swarms/structs/base_swarm.py b/swarms/structs/base_swarm.py index f91bb0af..f0a5d957 100644 --- a/swarms/structs/base_swarm.py +++ b/swarms/structs/base_swarm.py @@ -1,6 +1,6 @@ -import uuid import asyncio import json +import uuid from abc import ABC from concurrent.futures import ThreadPoolExecutor, as_completed from typing import ( @@ -14,11 +14,11 @@ from typing import ( import yaml +from swarms.memory.base_vectordb import BaseVectorDatabase from swarms.structs.agent import Agent from swarms.structs.conversation import Conversation -from swarms.utils.loguru_logger import logger from swarms.structs.omni_agent_types import AgentType -from swarms.memory.base_vectordb import BaseVectorDatabase +from swarms.utils.loguru_logger import logger class BaseSwarm(ABC): @@ -89,6 +89,7 @@ class BaseSwarm(ABC): speaker_selection_func: Optional[Callable] = None, rules: Optional[str] = None, collective_memory_system: Optional[BaseVectorDatabase] = False, + agent_ops_on: bool = False, *args, **kwargs, ): @@ -110,6 +111,7 @@ class BaseSwarm(ABC): self.speaker_selection_func = speaker_selection_func self.rules = rules self.collective_memory_system = collective_memory_system + self.agent_ops_on = agent_ops_on # Ensure that agents is exists if self.agents is None: @@ -170,6 +172,11 @@ class BaseSwarm(ABC): ) self.speaker_selection_func = speaker_selection_func + # Add the check for all the agents to see if agent ops is on! + if agent_ops_on is True: + for agent in self.agents: + agent.agent_ops_on = True + # Agents dictionary with agent name as key and agent object as value self.agents_dict = { agent.agent_name: agent for agent in self.agents @@ -697,3 +704,40 @@ class BaseSwarm(ABC): except Exception as error: logger.info(error) raise error + + def swarm_initialization(self, *args, **kwargs): + """ + Initializes the hierarchical swarm. + + Args: + *args: Additional positional arguments. + **kwargs: Additional keyword arguments. + + Returns: + None + + """ + logger.info(f"Initializing the hierarchical swarm: {self.name}") + logger.info(f"Purpose of this swarm: {self.description}") + + # Now log number of agnets and their names + logger.info(f"Number of agents: {len(self.agents)}") + logger.info( + f"Agent names: {[agent.name for agent in self.agents]}" + ) + + # Now see if agents is not empty + if len(self.agents) == 0: + logger.info("No agents found. Please add agents to the swarm.") + return None + + # Now see if director is not empty + if self.director is None: + logger.info( + "No director found. Please add a director to the swarm." + ) + return None + + logger.info( + f"Initialization complete for the hierarchical swarm: {self.name}" + ) diff --git a/swarms/structs/hiearchical_swarm.py b/swarms/structs/hiearchical_swarm.py index 610a1091..856ef80a 100644 --- a/swarms/structs/hiearchical_swarm.py +++ b/swarms/structs/hiearchical_swarm.py @@ -1,8 +1,17 @@ -import json -from typing import List +""" -# from beartype import beartype +Boss -> json containig orders in JSON -> list of agents -> send orders to every agent + +# Requirements +- Boss needs to know which agents are available [PROMPTING] +- Boss needs to output json commands sending tasks to every agent with the task and name +- Worker agents need to return a response to the boss +-> Boss returns the final output to the user +""" + +import json +from typing import List from swarms.structs.agent import Agent from swarms.structs.base_swarm import BaseSwarm from swarms.utils.loguru_logger import logger @@ -10,19 +19,6 @@ from pydantic import BaseModel, Field from swarms.structs.conversation import Conversation -class HiearchicalRequest(BaseModel): - task: str = Field( - None, - title="Task", - description="The task to send to the director agent.", - ) - agent_name: str = Field( - None, - title="Agent Name", - description="The name of the agent to send the task to.", - ) - - class HiearchicalRequestDict(BaseModel): task: str = Field( None, @@ -44,16 +40,6 @@ class HiearchicalRequestDict(BaseModel): } -""" -Boss -> json -> workers -> json -> Boss - - -Parse the JSON data and activate the selected agent. - -parse -> execute -""" - - class HiearchicalSwarm(BaseSwarm): """ A class representing a hierarchical swarm. @@ -86,6 +72,7 @@ class HiearchicalSwarm(BaseSwarm): long_term_memory_system: BaseSwarm = None, custom_parse_function: callable = None, rules: str = None, + custom_director_prompt: str = None, *args, **kwargs, ): @@ -98,6 +85,7 @@ class HiearchicalSwarm(BaseSwarm): self.long_term_memory_system = long_term_memory_system self.custom_parse_function = custom_parse_function self.rules = rules + self.custom_director_prompt = custom_director_prompt # Check to see agents is not empty self.agent_error_handling_check() @@ -119,6 +107,16 @@ class HiearchicalSwarm(BaseSwarm): time_enabled=True, *args, **kwargs ) + # Set the worker agents as tools for the director + for agent in self.agents: + self.director.add_tool(agent) + + # Set the has prompt for the director, + if custom_director_prompt is not None: + self.director.system_prompt = custom_director_prompt + else: + self.director.system_prompt = self.has_sop() + def swarm_initialization(self, *args, **kwargs): """ Initializes the hierarchical swarm. @@ -156,6 +154,23 @@ class HiearchicalSwarm(BaseSwarm): f"Initialization complete for the hierarchical swarm: {self.name}" ) + def agent_error_handling_check(self): + """ + Check if the agents list is not empty. + + Returns: + None + + Raises: + ValueError: If the agents list is empty. + + """ + if len(self.agents) == 0: + raise ValueError( + "No agents found. Please add agents to the swarm." + ) + return None + def find_agent_by_name(self, agent_name: str = None, *args, **kwargs): """ Finds an agent in the swarm by name. @@ -288,3 +303,54 @@ class HiearchicalSwarm(BaseSwarm): except Exception as e: logger.error(f"Error: {e}") raise e + + def run_worker_agent( + self, name: str = None, task: str = None, *args, **kwargs + ): + """ + Run the worker agent. + + Args: + name (str): The name of the worker agent. + task (str): The task to send to the worker agent. + + Returns: + str: The response from the worker agent. + + Raises: + Exception: If an error occurs while running the worker agent. + + """ + try: + # Find the agent by name + agent = self.find_agent_by_name(name) + + # Run the agent + response = agent.run(task, *args, **kwargs) + + return response + except Exception as e: + logger.error(f"Error: {e}") + raise e + + def has_sop(self): + # We need to check the name of the agents and their description or system prompt + # TODO: Provide many shot examples of the agents available and even maybe what tools they have access to + # TODO: Provide better reasoning prompt tiles, such as when do you use a certain agent and specific + # Things NOT to do. + return f""" + + You're a director boss agent orchestrating worker agents with tasks. Select an agent most relevant to + the input task and give them a task. If there is not an agent relevant to the input task then say so and be simple and direct. + These are the available agents available call them if you need them for a specific + task or operation: + + Number of agents: {len(self.agents)} + Agents Available: { + [ + {"name": agent.name, "description": agent.system_prompt} + for agent in self.agents + ] + } + + """ diff --git a/swarms/structs/mixture_of_agents.py b/swarms/structs/mixture_of_agents.py index d70fce54..b5869c35 100644 --- a/swarms/structs/mixture_of_agents.py +++ b/swarms/structs/mixture_of_agents.py @@ -5,6 +5,7 @@ from typing import List, Any from swarms.structs.conversation import Conversation from pydantic import BaseModel from swarms.utils.loguru_logger import logger +from swarms.memory.base_vectordb import BaseVectorDatabase class AgentRun(BaseModel): @@ -45,6 +46,7 @@ class MixtureOfAgents(BaseSwarm): final_agent: Agent = None, auto_save: bool = False, saved_file_name: str = "moe_swarm.json", + scp: BaseVectorDatabase = None, ): self.name = name self.description = description @@ -56,6 +58,7 @@ class MixtureOfAgents(BaseSwarm): self.final_agent = final_agent self.auto_save = auto_save self.saved_file_name = saved_file_name + self.scp = scp # Check the agents self.agent_check() @@ -70,6 +73,23 @@ class MixtureOfAgents(BaseSwarm): # Initialize the swarm self.swarm_initialization() + # Communication Protocol + self.communication_protocol() + + def communication_protocol(self): + try: + # Memory system + logger.info( + "Initializing SCP --- Swarm Communication Protocol" + ) + + if self.scp is not None: + for agent in self.agents.values(): + agent.long_term_memory = self.scp + logger.info("Agents have been integrated with SCP:") + except Exception as e: + logger.error(f"Error initializing SCP: {e}") + def agent_check(self): try: if not isinstance(self.agents, list): @@ -97,7 +117,7 @@ class MixtureOfAgents(BaseSwarm): Initializes the swarm by logging the swarm name, description, and the number of agents. """ # Name, description, and logger - logger.info(f"Initializing swarm {self.name}.") + logger.info(f"Initializing Mixture of Agents Swarm: {self.name}.") logger.info(f"Description: {self.description}") logger.info(f"Initializing swarm with {len(self.agents)} agents.") @@ -116,9 +136,11 @@ class MixtureOfAgents(BaseSwarm): logger.info(f"Running swarm {self.name}.") self.conversation.add("user", task) + # self.scp.add(f"User: {task}") # Conversation history history = self.conversation.return_history_as_string() + # self.scp.add(f"Conversation History: {history}") agent_runs = [] layer = 0 @@ -129,13 +151,16 @@ class MixtureOfAgents(BaseSwarm): responses = [] for agent in self.agents: out = agent.run(history, *args, **kwargs) + # self.scp.add( + # f"Agent: {agent.agent_name} Output: {out}" + # ) responses.append((agent.agent_name, out)) agent_runs.append( AgentRun(agent_name=agent.agent_name, output=out) ) # Log the agent run - logger.info(f"Agent {agent.agent_name} output: {out}") + # logger.info(f"Agent {agent.agent_name} output: {out}") # Add all the responses to the conversation logger.info("Adding responses to the conversation.") @@ -144,6 +169,7 @@ class MixtureOfAgents(BaseSwarm): # Update the history history = self.conversation.return_history_as_string() + # self.scp.add(f"Conversation History: {history}") layer += 1 @@ -154,6 +180,9 @@ class MixtureOfAgents(BaseSwarm): "Running the final output agent on the conversation history." ) final_output = self.final_agent.run(history, *args, **kwargs) + # self.scp.add( + # f"Final Agent: {self.final_agent.agent_name} Output: {final_output}" + # ) self.conversation.add( self.final_agent.agent_name, final_output ) diff --git a/swarms/structs/scp.py b/swarms/structs/scp.py index 2fda236e..1f531814 100644 --- a/swarms/structs/scp.py +++ b/swarms/structs/scp.py @@ -59,7 +59,7 @@ class SCP(BaseStructure): def __init__( self, - agents: List[AgentType], + agents: List[AgentType] = None, memory_system: BaseVectorDatabase = None, *args, **kwargs, diff --git a/swarms/tools/tool_dataset_generator.py b/swarms/tools/tool_dataset_generator.py new file mode 100644 index 00000000..a04cedbe --- /dev/null +++ b/swarms/tools/tool_dataset_generator.py @@ -0,0 +1,73 @@ +from typing import List +from swarms.structs.base_structure import BaseStructure +from swarms.tools.py_func_to_openai_func_str import ( + get_openai_function_schema_from_func, +) +from swarms.utils.loguru_logger import logger + + +class ToolDatasetGenerator(BaseStructure): + """ + Initialize the ToolDatasetGenerator. + + Args: + functions (List[callable], optional): List of functions to generate examples from. Defaults to None. + autosave (bool, optional): Flag to enable autosaving generated examples. Defaults to False. + output_files (List[str], optional): List of output file paths for autosaving. Defaults to None. + *args: Variable length argument list. + **kwargs: Arbitrary keyword arguments. + """ + + def __init__( + self, + functions: List[callable] = None, + autosave: bool = False, + output_files: List[str] = None, + verbose: bool = False, + *args, + **kwargs, + ): + super(ToolDatasetGenerator, self).__init__(*args, **kwargs) + self.functions = functions + self.autosave = autosave + self.output_files = output_files + self.verbose = verbose + + if self.verbose is True: + self.log_tool_metadata() + + def run(self, *args, **kwargs): + """ + Run the ToolDatasetGenerator. + + Args: + *args: Variable length argument list. + **kwargs: Arbitrary keyword arguments. + """ + try: + for function in self.functions: + function_str = get_openai_function_schema_from_func( + function + ) + logger.info(function_str) + if self.autosave: + for file in self.output_files: + with open(file, "a") as f: + f.write(function_str + "\n") + # agent_response = agent.run(sources_prompts) + # return agent_response + except Exception as e: + logger.info(f"An error occurred: {str(e)}") + + def log_tool_metadata(self): + """ + Log the number of tools and their metadata. + """ + try: + num_tools = len(self.functions) + logger.info(f"Number of tools: {num_tools}") + for i, function in enumerate(self.functions): + logger.info(f"Tool {i+1} metadata:") + logger.info(f"Name: {function.__name__}") + except Exception as e: + logger.info(f"An error occurred: {str(e)}") diff --git a/swarms/utils/streaming.py b/swarms/utils/streaming.py new file mode 100644 index 00000000..482208b4 --- /dev/null +++ b/swarms/utils/streaming.py @@ -0,0 +1,36 @@ +import time + + +def stream_response(response: str, delay: float = 0.1) -> None: + """ + Streams the response token by token. + + Args: + response (str): The response text to be streamed. + delay (float, optional): Delay in seconds between printing each token. Default is 0.1 seconds. + + Raises: + ValueError: If the response is not provided. + Exception: For any errors encountered during the streaming process. + + Example: + response = "This is a sample response from the API." + stream_response(response) + """ + # Check for required inputs + if not response: + raise ValueError("Response is required.") + + try: + # Stream and print the response token by token + for token in response.split(): + print(token, end=" ", flush=True) + time.sleep(delay) + print() # Ensure a newline after streaming + except Exception as e: + print(f"An error occurred during streaming: {e}") + + +# # Example usage +# response = "This is a sample response from the API." +# stream_response(response)