While iterating upon the design and development of this Congress.gov chatbot we balanced several functional and non-functional design criteria:
- Stale Data: Modified API calls to consistently fetch and prioritize the most recent data
- Temperature Tuning: Reduced the LLM temperature from 0.9 to 0.3 for more consistent, reliable outputs
- Enhanced API Support: Expanded support for additional Congress.gov API endpoints
- Caching System: Implemented a sophisticated caching mechanism to improve performance and data freshness
- Prompt Engineering: Refined prompt strategies for more accurate and timely responses
- UI/UX Enhancements: Added progress indicators and improved interface feedback
- Current Congress Knowledge: Provided explicit knowledge about the current 119th Congress
Lowered the temperature parameter used in LLM calls from 0.9 to 0.3 to produce more consistent, factual responses with less creative variation.
opts := []llms.CallOption{
llms.WithModel(model),
llms.WithTemperature(0.3), // Reduced from 0.9
llms.WithMaxTokens(2048),
}Expanded the Congress API client with additional endpoints to support more comprehensive data retrieval:
-
Added bill-related endpoints:
GetBillActions- For bill timeline and status informationGetBillCosponsors- For bill support informationGetBillRelatedBills- For finding similar legislation
-
Added member-related endpoints:
GetMemberSponsorship- For member-sponsored legislation
-
Added new data categories:
SearchCommitteesandGetCommittee- For committee informationSearchCongressionalRecord- For debate proceedings and speechesSearchNominations- For presidential nominationsSearchHearings- For congressional hearings
Implemented a thread-safe in-memory caching mechanism to:
- Reduce redundant API calls
- Improve response times
- Maintain data freshness with appropriate TTL (time-to-live)
// Cache provides a simple in-memory caching mechanism
type Cache struct {
data map[string]cacheEntry
mutex sync.RWMutex
}
type cacheEntry struct {
data map[string]interface{}
expiration time.Time
}Improved all prompts used for LLM interaction:
- System Prompt: Enhanced with stronger guidance on data recency and accuracy
- API Planning Prompt: Expanded to cover all available API endpoints with detailed selection criteria
- Response Interpretation Prompt: Improved with stronger emphasis on dates and current status
- Direct Response Prompt: Enhanced fallback responses to acknowledge limitations clearly
Modified search endpoints to prioritize recent data via explicit sort parameters:
params.Add("sort", "updateDate desc") // Sort by most recent updates
params.Add("sort", "date desc") // Sort by most recent dateImproved the user interface with loading indicators and disabled input during processing:
- Added a progress bar with animated fill to indicate processing status
- Implemented a spinning loader to provide visual feedback during API calls
- Disabled input fields and buttons during API requests to prevent duplicate submissions
- Added clear visual feedback when the interface is in a processing state
function setProcessingState(isProcessing) {
if (isProcessing) {
// Disable input and buttons
userInput.disabled = true;
sendButton.disabled = true;
clearButton.disabled = true;
// Add visual indication that buttons are disabled
sendButton.classList.add('opacity-50', 'cursor-not-allowed');
clearButton.classList.add('opacity-50', 'cursor-not-allowed');
// Show progress indicators
progressContainer.classList.remove('hidden');
// Animate progress bar
progressBarFill.style.width = '5%';
setTimeout(() => { progressBarFill.style.width = '30%'; }, 500);
setTimeout(() => { progressBarFill.style.width = '70%'; }, 1500);
} else {
// Enable input and buttons, reset visual state
// ...
}
}Added explicit knowledge about the current congressional session to the system prompt:
CURRENT CONGRESS INFORMATION:
- The current Congress is the 119th Congress (2025-2026)
- The previous Congress was the 118th Congress (2023-2024)
- The House of Representatives has 435 voting members
- The Senate has 100 members (2 from each state)
- The current Speaker of the House is Mike Johnson (as of April 2025)
- The current Senate Majority Leader is Chuck Schumer (as of April 2025)
- The current Senate Minority Leader is Mitch McConnell (as of April 2025)
This knowledge ensures the LLM will query for data from the current congress when not otherwise specified, significantly improving the relevance and currency of responses.
These improvements collectively result in:
- More Accurate and Current Information: Users now receive the most up-to-date available data
- Consistent Responses: The lower temperature setting produces more reliable, factually-grounded answers
- Broader Information Access: The expanded API support allows for more comprehensive answers
- Improved Performance: Caching reduces redundant API calls and improves response times
- Better User Experience: More detailed and accurate responses with clear indications of data freshness
Potential future improvements include:
- Implementing proactive cache invalidation for critical data
- Adding streaming responses for more interactive conversations
- Expanding the error handling and retry mechanisms
- Implementing a monitoring system for API call analytics
- Adding automatic bill status tracking for important legislation