-
Notifications
You must be signed in to change notification settings - Fork 16
/
agents.py
98 lines (88 loc) · 3.55 KB
/
agents.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import streamlit as st
from crewai import Agent
from tools.search_tools import basic_search, PerplexityAIChatTool
from tools.you_search_tools import AISnippetsSearchTool
from langchain_groq import ChatGroq
from langchain_anthropic import ChatAnthropic
you_search_tool = AISnippetsSearchTool()
pplx = PerplexityAIChatTool()
def streamlit_callback(step_output):
"""Callback function to display step output in Streamlit."""
st.markdown("---")
for step in step_output:
if isinstance(step, tuple) and len(step) == 2:
action, observation = step
if isinstance(
action, dict
) and "tool" in action and "tool_input" in action and "log" in action:
st.markdown(f"# Action")
st.markdown(f"**Tool:** {action['tool']}")
st.markdown(f"**Tool Input:** {action['tool_input']}")
st.markdown(f"**Log:** {action['log']}")
if 'Action' in action: # Check if 'Action' key exists before using it
st.markdown(f"**Action:** {action['Action']}")
st.markdown(f"**Action Input:** ```json\n{action['tool_input']}\n```")
elif isinstance(action, str):
st.markdown(f"**Action:** {action}")
else:
st.markdown(f"**Action:** {str(action)}")
st.markdown(f"**Observation**")
if isinstance(observation, str):
observation_lines = observation.split('\n')
for line in observation_lines:
st.markdown(line)
else:
st.markdown(str(observation))
else:
st.markdown(step)
class PolicyAgents():
def __init__(self):
self.llm = ChatGroq( #api_key=os.getenv("GROQ_API_KEY"),
model="llama-3.1-70b-versatile")
#model="llama3-8b-8192")
#anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
#self.llm = ChatAnthropic(anthropic_api_key=anthropic_api_key,
# model_name="claude-3-haiku-20240307")
def research_agent(self):
return Agent(
role='Policy Researcher',
goal=
'Investigate current policy issues, trends, and evidence through comprehensive web and database searches to gather relevant data and insights.',
tools=[basic_search],
backstory=
'An expert in navigating complex policy landscapes to extract critical data and insights from a multitude of sources.',
verbose=True,
llm=self.llm,
step_callback=streamlit_callback,
allow_delegation=False,
max_iter=3,
)
def writer_agent(self):
return Agent(
role='Policy Writer',
goal=
'Use insights from the Policy Researcher to create a detailed, engaging, and impactful policy brief.',
tools=[basic_search],
backstory=
'Skilled in crafting impactful policy briefs that articulate insights, key trends, and evidence-based recommendations.',
verbose=True,
llm=self.llm,
allow_delegation=False,
step_callback=streamlit_callback,
max_iter=5,
)
def review_agent(self):
return Agent(
role='Policy Brief Reviewer',
goal=
'Critically review the draft policy brief for coherence, alignment with policy objectives, evidence strength, and persuasive clarity. Refine content to ensure high-quality, impactful communication.',
#tools=[basic_search],
backstory=
'A meticulous reviewer with a keen understanding of policy advocacy, ensuring each brief is clear, compelling, and grounded in solid evidence.',
verbose=True,
llm=self.llm,
allow_delegation=False,
step_callback=streamlit_callback,
max_iter=5,
)