Skip to content

Commit

Permalink
Updated human intercation
Browse files Browse the repository at this point in the history
  • Loading branch information
DomGrieco committed Dec 8, 2024
1 parent 83b1137 commit 36058a0
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 30 deletions.
7 changes: 6 additions & 1 deletion democracy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ This agent system combines modern congressional data with historical constitutio

## Setup

1. Install dependencies:
1. Install dependencies:
```
## Interactive Usage
Run the interactive analysis tool:
53 changes: 53 additions & 0 deletions democracy/analyses/recent-bills-became-law-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Original Query: what bills recemtly became law?
Interpreted Query: ```
Find and analyze the most recently enacted bills.
For each bill that became law:
1. List the bill number and title
2. Show the date enacted
3. Summarize key provisions
4. Explain the impact
Sort by most recent first.
```

Analysis:

Running:
- transfer_task_to_modern_congress_analyst(task_description=Identify and analyze the most recently enacted bills by the U.S. Congress., expected_output=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=...)


Running:
- get_chat_history(num_chats=1)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=...)

Having analyzed the recent legislation from both a modern and founding fathers' perspective, here are some interesting contrasts and insights:

1. **Disapproving the D.C. Council's Revised Criminal Code Act of 2022**:
- **Modern Perspective**: This action underscores federal authority over the District of Columbia, preserving existing sentencing laws.
- **Founding Fathers' Perspective**: The founders designed D.C. to be under federal control, consistent with Congress's disapproval to maintain national oversight.
- **Contrast**: Modern democratic principles emphasize local governance; however, the founders' design purposefully limits D.C.'s local autonomy to ensure neutrality and cohesion at the nation's capital.

2. **Termination of the Covid-19 National Emergency**:
- **Modern Perspective**: Ends extended executive powers, signaling a return to normalcy post-pandemic.
- **Founding Fathers' Perspective**: Aligns with checks and balances, ensuring executive power is not unchecked and respects state sovereignty.
- **Contrast**: While today's federal responses are more structured, the foundational concern for balanced power and civil liberties persists as highly relevant.

3. **Broader Insights**:
- The federal oversight of D.C. and the termination of national emergencies both highlight an enduring constitutional tension between concentrated power and decentralized federalism.
- The founding fathers' principles, especially concerning separation of powers and federal balance, continue to reflect in modern legislative processes, revealing their timeless impact on governance.

These analyses demonstrate the founding fathers' foresight in designing a system that requires constant negotiation between national unity and local autonomy, a balance still imperative in today's legislative landscape.
59 changes: 59 additions & 0 deletions democracy/analyses/recent-bills-became-law-3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Original Query: what bills recently became law?
Interpreted Query: ```
Using our Congress.gov knowledge base:
1. Find the most recently enacted bills from our current data
2. For each enacted bill:
- List the bill number and exact title
- Show the exact date enacted
- Include the latest action status
- Summarize key provisions
- Explain current impact
Sort by most recent enactment date.
```

Analysis:

Running:
- transfer_task_to_modern_congress_analyst(task_description=..., expected_output=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=...)
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=Bill HR.8150 or REVAMP Act focuses on community development and infrastructure projects.)
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=Bill HR.5349 mandates educational content on communism's historical impact.)

### Summary of Modern Legislation

1. **Bill S.3960**
- **Title**: A bill to amend title 35, United States Code, to provide a good faith exception to the imposition of fines for false assertions and certifications.
- **Date of Enactment**: Presented to President on December 6, 2024
- **Summary**: This bill proposes an amendment allowing a good faith exception in legal proceedings involving false claims related to Title 35. This could reduce penalties for entities acting in presumed good faith while making inaccurate assertions.

2. **Bill HR.8150 (REVAMP Act)**
- **Summary**: Intended to boost infrastructure and community renewal, focusing on urban development and bridging economic disparities.

3. **Bill HR.5349**
- **Summary**: Mandates educational content on communism's impact, affecting school curricula to include historical and ideological discussions on communism.

### Constitutional Perspectives by Founding Fathers

1. **Bill S.3960 Analysis**
- **Constitutional Concerns**: The founding fathers, particularly figures like James Madison, emphasized rule of law and accountability. A "good faith exception" could challenge the separation of powers by potentially limiting judicial oversight.
- **Federalism**: It may impinge on both federal and state judicial processes by altering accountability standards.
- **Separation of Powers**: This exception could lead to reduced checks and balances, an area of concern for framers who designed these mechanisms to prevent governmental overreach.

2. **Bill HR.8150 (REVAMP Act) Analysis**
- **Federalism**: The focus on infrastructure implicates federal-state power dynamics, with founding figures like Madison advocating for clear demarcation. Federal involvement in traditionally state-led projects could raise state sovereignty issues.
- **Constitutional Powers**: Madison's emphasis on enumerated federal powers suggests skepticism over federal action in areas not expressly stated in the Constitution unless justified under the general welfare clause.

### Interesting Contrasts

- **Bill S.3960 vs. Founding Principles**: The modern attempt to introduce flexibility through a good faith exception contrasts with the founding fathers' emphasis on strict legal accountability and oversight, potentially disrupting judicial balances crucial for preventing abuses of power.

- **Bill HR.8150 vs. Founding Federalism**: The REVAMP Act's expansive federal role in infrastructure may differ from original visions of federalism, which prioritized state responsibilities for local projects unless necessitated by broader national interests.

These legislative developments reflect modern complexities and societal needs, requiring careful alignment with constitutional architecture as envisioned by the founding fathers.
41 changes: 41 additions & 0 deletions democracy/analyses/recent-bills-became-law.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Query: Most recent bills that have become law

Analysis:

Running:
- transfer_task_to_modern_congress_analyst(task_description=..., expected_output=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=...)


Running:
- transfer_task_to_constitutional_perspective_analyst(task_description=..., expected_output=..., extra_data=Termination of COVID-19 National Emergency)

Here's the constitutional analysis of the recent termination of the COVID-19 National Emergency, from the perspective of the founding fathers:

### Termination of COVID-19 National Emergency

**Historical Constitutional Perspective:**
- **Executive Powers:** Founders like Alexander Hamilton supported a strong executive for crisis management (Federalist No. 70) but also emphasized checks and balances. The termination signifies Congress reclaiming oversight authority, ensuring no unchecked executive power persists, aligning with principles James Madison advocated (Federalist No. 51).

- **Federalism:** The founding fathers valued a balance between state and federal powers (10th Amendment), wary of centralized control. Ending the emergency returns more autonomy to states, respecting the federalism balance crucial to Madison's vision for diversified government power structures.

- **Original Intent:** While the founders saw the need for quick executive response during crises, prolonged powers without legislative oversight were discouraged. They likely intended for emergency powers to be temporary, making this termination a return to constitutional norms with Congress engaged in legislative responsibilities.

### Conclusion

The founding fathers would likely approve of the termination as a restoration of constitutional checks, emphasizing legislative control and federal balance. This move aligns with their principles, designed to prevent extended executive reach without representative oversight. I will analyze additional legislation in subsequent segments if needed.
10 changes: 6 additions & 4 deletions democracy/historical_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ def read(self, url: str) -> List[Document]:
knowledge=knowledge_base,
tools=[DuckDuckGo(), Newspaper4k()],
instructions=[
"Analyze current congressional bills and activities objectively",
"Focus on summarizing key points, impact, and status",
"Provide clear explanations without historical interpretation",
"Use ONLY the data from our Congress.gov knowledge base for current information",
"When analyzing recent bills, focus on actual enactment dates and current status",
"Provide specific bill numbers, dates, and exact titles from our knowledge base",
"Do not rely on training data for current legislative information",
"Focus on summarizing key points, impact, and status from our current data",
],
)

Expand Down Expand Up @@ -194,7 +196,7 @@ def read(self, url: str) -> List[Document]:
)

# Configuration flags
TEST_KNOWLEDGE_ONLY = True # Set to False to run full agent analysis
TEST_KNOWLEDGE_ONLY = False # Set to False to run full agent analysis

def load_knowledge_bases(force_reload=False):
"""Load all knowledge bases"""
Expand Down
90 changes: 65 additions & 25 deletions democracy/interactive_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,64 @@
congress_analysis_team,
load_knowledge_bases
)
from phi.assistant import Assistant
from phi.utils.pprint import pprint_run_response
from pathlib import Path

# Create query interpreter assistant
query_interpreter = Assistant(
name="Query Interpreter",
instructions=[
"You analyze user queries about congressional legislation and format them for detailed analysis.",
"Identify the main intent and structure the query appropriately.",
"Format queries to be specific and detailed for the analysis team."
],
debug_mode=True
)

def preprocess_query(query: str) -> str:
"""Use LLM to interpret and format the query appropriately"""
try:
response = query_interpreter.run(f"""
Analyze this user query about congressional legislation: "{query}"
Important: Use ONLY the data from our Congress.gov knowledge base, which contains current 2024 data.
Do not rely on training data or historical knowledge.
1. Identify the main intent (e.g., recent laws, specific bill analysis, topic analysis)
2. Format an appropriate query for the analysis team
For example:
If asking about recent laws, format like this:
```
Using our Congress.gov knowledge base:
1. Find the most recently enacted bills from our current data
2. For each enacted bill:
- List the bill number and exact title
- Show the exact date enacted
- Include the latest action status
- Summarize key provisions
- Explain current impact
Sort by most recent enactment date.
```
Return only the formatted query as a clear, specific request.
""", stream=False)

return str(response)
except Exception as e:
print(f"Error preprocessing query: {str(e)}")
return query

def interactive_analysis():
"""Interactive CLI for natural language congressional analysis"""
print("\nWelcome to the Congressional Analysis System")
print("------------------------------------------")
print("Ask any question about Congress, bills, or constitutional implications.")
print("Examples:")
print("- What are the recent gun control bills and their constitutional implications?")
print("- Analyze healthcare legislation from 2023")
print("- What bills recently became law?")
print("- Tell me about recent gun control legislation")
print("- What would the founding fathers think about H.R. 1234?")
print("- Compare recent privacy laws with constitutional principles")

# Ensure knowledge bases are loaded
load_knowledge_bases(force_reload=False)
Expand All @@ -25,39 +71,33 @@ def interactive_analysis():
analyses_dir.mkdir(exist_ok=True, parents=True)

while True:
# Get natural language query from user
query = input("\nWhat would you like to know? (or 'exit' to quit): ")

if query.lower() == 'exit':
print("\nThank you for using the Congressional Analysis System.")
break

try:
# Let the LLM handle query interpretation and analysis
analysis = congress_analysis_team.run(f"""
Analyze the following query about congressional legislation
and provide both modern and historical constitutional perspectives:
{query}
Consider:
- Relevant bills and their status
- Constitutional implications
- Historical context
- Current impact
""")
# Preprocess query using LLM
formatted_query = preprocess_query(query)
print("\nInterpreted Query:", formatted_query)

# Run analysis with formatted query and handle streaming
print("\nAnalysis Results:")
print("----------------")
print(analysis.content)
analysis_content = ""
for chunk in congress_analysis_team.run(formatted_query, stream=True):
if hasattr(chunk, 'content') and chunk.content:
analysis_content += chunk.content
print(chunk.content, end="", flush=True)

# Option to save
save = input("\nWould you like to save this analysis? (y/n): ")
if save.lower() == 'y':
filename = input("Enter filename to save as: ")
with open(analyses_dir / f"{filename}.txt", "w") as f:
f.write(f"Query: {query}\n\nAnalysis:\n{analysis.content}")
print(f"Analysis saved to analyses/{filename}.txt")
if analysis_content:
save = input("\n\nWould you like to save this analysis? (y/n): ")
if save.lower() == 'y':
filename = input("Enter filename to save as: ")
with open(analyses_dir / f"{filename}.txt", "w") as f:
f.write(f"Original Query: {query}\nInterpreted Query: {formatted_query}\n\nAnalysis:\n{analysis_content}")
print(f"Analysis saved to analyses/{filename}.txt")

except Exception as e:
print(f"\nError processing query: {str(e)}")
Expand Down

0 comments on commit 36058a0

Please sign in to comment.