File size: 1,355 Bytes
ae43d88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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,
		)