[Python] CrewAI Deployment Issue with Permisson in AWS Lambda

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    Good day all, I have a fastapi application API's that connect to my CrewAI agents. It is working fine as expected in local. The CrewAI agent uses the PDFSearchTool of CrewAI. The PDFSearchTool create a vector DB of the PDF that is connected. So the code creates a folder 'db\' parallel to main.py.

    Now I am trying to deploy this application to AWS Lambda. But when I deployed my container to Lambda, I started getting exceptions. So I realized we can only create folders inside the 'temp\' folder. To change the position of the data creating I added few lines to the code but still getting the same error.

    The added codes are:

    #in main.py:
    # Override default config directory
    import os
    os.environ["MEM0_DIR"] = "/tmp/mem0_config"
    os.environ["CONFIG_DIR"] = "/tmp/embedchain"
    os.environ["EMBEDCHAIN_CONFIG_DIR"] = "/tmp/.embedchain"
    os.environ["CHROMA_DB_DIR"] = "/tmp/db"


    #in crew.py
    import os
    from chromadb.config import Settings
    chroma_settings = Settings(
    chroma_db_impl="chromadb.db.impl.sqlite",
    persist_directory="/tmp/db" # This is the correct field name
    )

    os.environ["CHROMA_DB_DIR"] = "/tmp/db"
    os.makedirs("/tmp/db", exist_ok=True)

    from app.config.config import Config
    from crewai_tools import PDFSearchTool
    from crewai import Agent, Crew, Process, Task
    from crewai.project import CrewBase, agent, crew, task
    from app.utils.helper.agent_settings import get_verbose_config

    from embedchain import App
    embedchain_app = App(config={"chroma_settings": chroma_settings})

    pdf_file = Config.get_env_path("PDF_PATH")


    @CrewBase
    class SomeCrew():

    agents_config = 'config/agents.yaml'
    tasks_config = 'config/tasks.yaml'

    # Get the information from environment
    setup_verbose = get_verbose_config()
    pdf_tools = PDFSearchTool(pdf=pdf_file, app=embedchain_app)


    @agent
    def some_agent(self) -> Agent:
    return Agent(
    config=self.agents_config['some_agent'],
    tools=[
    self.pdf_tools
    ],
    verbose=self.setup_verbose
    )

    @task
    def some_task(self) -> Task:
    ....

    @crew
    def crew(self) -> Crew:
    ....



    And the error I am still getting is,

    {
    "errorMessage": "Unable to generate pydantic-core schema for <class 'crewai_tools.tools.stagehand_tool.stagehand_tool.AvailableModel'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.\n\nIf you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.\n\nFor further information visit https://errors.pydantic.dev/2.11/u/schema-for-unknown-type",
    "errorType": "PydanticSchemaGenerationError",
    "requestId": "",
    "stackTrace": [
    " File \"/var/lang/lib/python3.12/importlib/__init__.py\", line 90, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n",
    " File \"<frozen importlib._bootstrap>\", line 1387, in _gcd_import\n",
    " File \"<frozen importlib._bootstrap>\", line 1360, in _find_and_load\n",
    " File \"<frozen importlib._bootstrap>\", line 1331, in _find_and_load_unlocked\n",
    " File \"<frozen importlib._bootstrap>\", line 935, in _load_unlocked\n",
    " File \"<frozen importlib._bootstrap_external>\", line 999, in exec_module\n",
    " File \"<frozen importlib._bootstrap>\", line 488, in _call_with_frames_removed\n",
    " File \"/var/task/main.py\", line 23, in <module>\n from app.api.agent.router import router as agent_router\n",
    " File \"/var/task/app/api/agent/router.py\", line 2, in <module>\n from app.api.agent.some_agent import router as some_agent_router\n",
    " File \"/var/task/app/api/agent/some_agent.py\", line 4, in <module>\n from app.agents.somaeagent.some_crew import SomeCrew\n",
    " File \"/var/task/app/agents/something/some_crew.py\", line 3, in <module>\n from crewai_tools import PDFSearchTool\n",
    " File \"/var/lang/lib/python3.12/site-packages/crewai_tools/__init__.py\", line 9, in <module>\n from .tools import (\n",
    " File \"/var/lang/lib/python3.12/site-packages/crewai_tools/tools/__init__.py\", line 70, in <module>\n from .stagehand_tool.stagehand_tool import StagehandTool\n",
    " File \"/var/lang/lib/python3.12/site-packages/crewai_tools/tools/stagehand_tool/__init__.py\", line 1, in <module>\n from .stagehand_tool import StagehandTool\n",
    " File \"/var/lang/lib/python3.12/site-packages/crewai_tools/tools/stagehand_tool/stagehand_tool.py\", line 90, in <module>\n class StagehandTool(BaseTool):\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py\", line 237, in __new__\n complete_model_class(\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py\", line 597, in complete_model_class\n schema = gen_schema.generate_schema(cls)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 706, in generate_schema\n schema = self._generate_schema_inner(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 999, in _generate_schema_inner\n return self._model_schema(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 832, in _model_schema\n {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1201, in _generate_md_field_schema\n common_field = self._common_field_schema(name, field_info, decorators)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1367, in _common_field_schema\n schema = self._apply_annotations(\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 2279, in _apply_annotations\n schema = get_inner_schema(source_type)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py\", line 83, in __call__\n schema = self._handler(source_type)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 2261, in inner_handler\n schema = self._generate_schema_inner(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1004, in _generate_schema_inner\n return self.match_type(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1118, in match_type\n return self._match_generic_type(obj, origin)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1141, in _match_generic_type\n return self._union_schema(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1429, in _union_schema\n choices.append(self.generate_schema(arg))\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 706, in generate_schema\n schema = self._generate_schema_inner(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1004, in _generate_schema_inner\n return self.match_type(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 1122, in match_type\n return self._unknown_type_schema(obj)\n",
    " File \"/var/lang/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py\", line 634, in _unknown_type_schema\n raise PydanticSchemaGenerationError(\n"
    ]
    }


    Can anyone please help me to resolve the issue?

    Continue reading...

Compartilhe esta Página