geekphoenix's picture
Update crew.py
542a359 verified
from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, crew, task
from tools.custom_tool import landing_ai_document_analysis
import os
@CrewBase
class DocProcessing():
"""DocProcessing crew for document analysis"""
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'
def __init__(self):
"""Initialize the DocProcessing crew with API key validation."""
super().__init__()
# Get API key from environment variable (set at runtime)
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
if not anthropic_api_key:
raise ValueError("ANTHROPIC_API_KEY environment variable is required")
self.llm = LLM(
model="claude-3-haiku-20240307",
api_key=anthropic_api_key,
temperature=0,
)
@agent
def document_analyst(self) -> Agent:
return Agent(
config=self.agents_config['document_analyst'],
verbose=True,
tools=[landing_ai_document_analysis],
llm=self.llm,
)
@task
def document_analysis(self) -> Task:
return Task(
config=self.tasks_config['document_analysis'],
)
@crew
def crew(self) -> Crew:
"""Creates the DocProcessing crew"""
return Crew(
agents=self.agents, # Automatically created by the @agent decorator
tasks=self.tasks, # Automatically created by the @task decorator
process=Process.sequential,
verbose=True,
)