|
4 | 4 | import importlib
|
5 | 5 |
|
6 | 6 | # get environment variables
|
7 |
| -agent_framework = os.getenv("AGENT_FRAMEWORK", "pydantic_ai") |
8 | 7 | agent_module = os.getenv("AGENT_MODULE", "agent")
|
9 | 8 | agent_class = os.getenv("AGENT_CLASS", "agent")
|
10 | 9 | security_module = os.getenv("SECURITY_MODULE", None)
|
|
19 | 18 | if security_class == '':
|
20 | 19 | security_class = None
|
21 | 20 |
|
22 |
| -# dynamically import agent framework |
23 |
| -if agent_framework == "pydantic-ai": |
24 |
| - from fastapi_agents.pydantic_ai import PydanticAIAgent as AgentWrapper |
25 |
| - from pydantic_ai import Agent as BaseAgentClass |
26 |
| -elif agent_framework == "smolagents": |
27 |
| - from fastapi_agents.smolagents import SmolagentsAgent as AgentWrapper |
28 |
| - from smolagents import MultiStepAgent as BaseAgentClass |
29 |
| -elif agent_framework == "llama-index": |
30 |
| - from fastapi_agents.llama_index import LlamaIndexAgent as AgentWrapper |
31 |
| - from llama_index.core.agent.types import BaseAgent as BaseAgentClass |
32 |
| -elif agent_framework == "crewai": |
33 |
| - from fastapi_agents.crewai import CrewAIAgent as AgentWrapper |
34 |
| - from crewai import Crew as BaseAgentClass |
35 |
| -else: |
36 |
| - raise ValueError(f"Unknown agent framework: {agent_framework}") |
37 |
| - |
38 | 21 | # create FastAPI app and FastAPIAgents instance
|
39 | 22 | app = FastAPI()
|
40 | 23 | agents = FastAPIAgents(path_prefix=api_prefix, mode=api_mode)
|
|
43 | 26 | import_agent_module = importlib.import_module(agent_module)
|
44 | 27 | agent = getattr(import_agent_module, agent_class)
|
45 | 28 |
|
46 |
| -# check type of agent |
47 |
| -if not issubclass(type(agent), BaseAgentClass): |
48 |
| - raise ValueError(f"Agent must be a subclass of {type(BaseAgentClass)}, not {agent}") |
49 |
| - |
50 | 29 | # dynamically import security module
|
51 | 30 | if security_class and security_module:
|
52 | 31 | import_security_module = importlib.import_module(security_module)
|
|
59 | 38 | # register agent with FastAPIAgents
|
60 | 39 | agents.register(
|
61 | 40 | api_endpoint,
|
62 |
| - AgentWrapper(agent), |
| 41 | + agent, |
63 | 42 | security_dependency=security
|
64 | 43 | )
|
65 | 44 | app.include_router(agents)
|
0 commit comments