kyegomez / swarms

The Enterprise-Grade Production-Ready Multi-Agent Orchestration Framework Join our Community: https://discord.com/servers/agora-999382051935506503
https://docs.swarms.world
GNU Affero General Public License v3.0
1.81k stars 247 forks source link

How to fully save and load an agent #640

Open snakelu opened 4 days ago

snakelu commented 4 days ago

The tokenizer, long_termmamory, logger handler, agent_output, and executor properties are not serializable. If I save the agent and then load it from the save file, these five properties in my agent cannot be restored to their pre save state.

My agent state file contains the following content:

{
    "agent_id": "d35cc8689e8f4402b88bac083feba0fd",
    "id": "1f9e99b08d0a4a99970572cb2455d973",
    "llm": {
        "name": "OpenAIChatLLM",
        "doc": null
    },
    "template": null,
    "max_loops": 1,
    "stopping_condition": null,
    "loop_interval": 0,
    "retry_attempts": 1,
    "retry_interval": 1,
    "task": null,
    "stopping_token": "<DONE>",
    "interactive": false,
    "dashboard": false,
    "return_history": false,
    "dynamic_temperature_enabled": true,
    "dynamic_loops": false,
    "user_name": "test_user",
    "context_length": 200000,
    "sop": null,
    "sop_list": null,
    "tools": null,
    "system_prompt": "This is a test agent",
    "agent_name": "test",
    "agent_description": null,
    "saved_state_path": "test_state.json",
    "autosave": true,
    "response_filters": [],
    "self_healing_enabled": false,
    "code_interpreter": false,
    "multi_modal": null,
    "pdf_path": null,
    "list_of_pdf": null,
    "tokenizer": "<Non-serializable: TikTokenizer>",
    "long_term_memory": "<Non-serializable: ChromaDB>",
    "preset_stopping_token": false,
    "traceback": null,
    "traceback_handlers": null,
    "streaming_on": false,
    "docs": null,
    "docs_folder": null,
    "verbose": true,
    "parser": null,
    "best_of_n": null,
    "callback": null,
    "metadata": null,
    "callbacks": null,
    "logger_handler": "<Non-serializable: TextIOWrapper>",
    "search_algorithm": null,
    "logs_to_filename": null,
    "evaluator": null,
    "stopping_func": null,
    "custom_loop_condition": null,
    "sentiment_threshold": null,
    "custom_exit_command": "exit",
    "sentiment_analyzer": null,
    "limit_tokens_from_string": null,
    "tool_schema": null,
    "output_type": "json",
    "function_calling_type": "json",
    "output_cleaner": null,
    "function_calling_format_type": "OpenAI",
    "list_base_models": null,
    "metadata_output_type": "json",
    "state_save_file_type": "json",
    "chain_of_thoughts": false,
    "algorithm_of_thoughts": false,
    "tree_of_thoughts": false,
    "tool_choice": "auto",
    "execute_tool": false,
    "planning": false,
    "planning_prompt": null,
    "custom_planning_prompt": null,
    "rules": null,
    "custom_tools_prompt": null,
    "memory_chunk_size": 2000,
    "agent_ops_on": false,
    "log_directory": null,
    "tool_system_prompt": "\n\n\n    You've been granted tools to assist users by always providing outputs in JSON format for tool usage. \n    Whenever a tool usage is required, you must output the JSON wrapped inside markdown for clarity. \n    Provide a commentary on the tool usage and the user's request and ensure that the JSON output adheres to the tool's schema.\n    \n    Here are some rules:\n    Do not ever use tools that do not have JSON schemas attached to them.\n    Do not use tools that you have not been granted access to.\n    Do not use tools that are not relevant to the task at hand.\n    Do not use tools that are not relevant to the user's request.\n    \n    \n    Here are the guidelines you must follow:\n\n    1. **Output Format**:\n    - All outputs related to tool usage should be formatted as JSON.\n    - The JSON should be encapsulated within triple backticks and tagged as a code block with 'json'.\n\n    2. **Schema Compliance**:\n    - Ensure that the JSON output strictly follows the provided schema for each tool.\n    - Each tool's schema will define the structure and required fields for the JSON output.\n\n    3. **Schema Example**:\n    If a tool named `example_tool` with a schema requires `param1` and `param2`, your response should look like:\n    ```json\n    {\n        \"type\": \"function\",\n        \"function\": {\n        \"name\": \"example_tool\",\n        \"parameters\": {\n            \"param1\": 123,\n            \"param2\": \"example_value\"\n        }\n        }\n    }\n    ```\n\n    4. **Error Handling**:\n    - If there is an error or the information provided by the user is insufficient to generate a valid JSON, respond with an appropriate error message in JSON format, also encapsulated in markdown.\n\n    Remember, clarity and adherence to the schema are paramount. Your primary goal is to ensure the user receives well-structured JSON outputs that align with the tool's requirements.\n\n    ---\n\n    Here is the format you should always follow for your responses involving tool usage:\n\n    ```json\n    {\n    \"type\": \"function\",\n    \"function\": {\n        \"name\": \"<tool_name>\",\n        \"parameters\": {\n            \"param1\": \"<value1>\",\n            \"param2\": \"<value2>\"\n        }\n    }\n    }\n    ```\n\n    Please proceed with your task accordingly.\n\n    ",
    "max_tokens": 8000,
    "frequency_penalty": 0.0,
    "presence_penalty": 0.0,
    "temperature": 0.1,
    "workspace_dir": "agent_workspace",
    "timeout": null,
    "created_at": 1732242276.3805494,
    "return_step_meta": true,
    "tags": null,
    "use_cases": null,
    "name": "test",
    "description": null,
    "agent_output": "<Non-serializable: ManySteps>",
    "step_pool": [],
    "print_every_step": false,
    "time_created": "2024-11-22 10:24:36",
    "data_memory": null,
    "load_yaml_path": null,
    "auto_generate_prompt": false,
    "rag_every_loop": false,
    "plan_enabled": false,
    "artifacts_on": true,
    "artifacts_output_path": "test",
    "artifacts_file_extension": ".txt",
    "device": "cpu",
    "all_cores": true,
    "device_id": 0,
    "scheduled_run_date": null,
    "do_not_use_cluster_ops": true,
    "all_gpus": false,
    "short_memory": [
        {
            "role": "System: ",
            "content": "This is a test agent",
            "timestamp": "2024-11-22 10:24:49"
        },
        {
            "role": "test_user",
            "content": "hello",
            "timestamp": "2024-11-22 10:25:14"
        },
        {
            "role": "Database",
            "content": "Documents Available: []\n",
            "timestamp": "2024-11-22 10:25:14"
        }
    ],
    "feedback": [],
    "executor": "<Non-serializable: ThreadPoolExecutor>"
}

Upvote & Fund

Fund with Polar

github-actions[bot] commented 4 days ago

Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.