Agent
class is the core agent implementation in Upsonic, providing a powerful and flexible interface for creating AI agents with advanced capabilities including memory management, safety policies, reliability layers, and sophisticated tool integration.
Table of Contents
Creating an Agent
TheAgent
can be created with minimal configuration or with extensive customization to suit your specific needs. The agent provides a robust foundation for AI-powered applications with built-in support for various advanced features.
Basic Agent Creation
The simplest way to create an agent is with default settings:"openai/gpt-4o"
. Make sure you have the appropriate API key set in your environment.
Agent with Custom Configuration
For more control over your agent’s behavior, you can specify various parameters:Agent with Company Information
You can provide company context to help the agent understand your organization:Agent Attributes
TheAgent
exposes numerous attributes that control its behavior and capabilities. Understanding these attributes is crucial for effective agent configuration.
Core Identity Attributes
Attribute | Type | Default | Description |
---|---|---|---|
name | str | None | None | Human-readable name for the agent |
agent_id_ | str | None | None | Unique identifier for the agent instance |
model_provider | BaseModelProvider | None | OpenAI("gpt-4o") | The underlying LLM provider |
Model and Performance Attributes
Attribute | Type | Default | Description |
---|---|---|---|
model | Union[str, BaseModelProvider] | "openai/gpt-4o" | Model specification (string or provider instance) |
retry | int | 1 | Number of retry attempts for failed calls |
mode | RetryMode | "raise" | Retry behavior: “raise” or “return_false” |
debug | bool | False | Enable debug mode for detailed logging |
Company Context Attributes
Attribute | Type | Default | Description |
---|---|---|---|
company_url | str | None | None | Company website URL |
company_objective | str | None | None | Company’s main objective |
company_description | str | None | None | Detailed company description |
Role and Professional Attributes
Attribute | Type | Default | Description |
---|---|---|---|
role | str | None | None | Professional role of the agent |
goal | str | None | None | Primary goal or objective |
instructions | str | None | None | Specific instructions for behavior |
education | str | None | None | Educational background |
work_experience | str | None | None | Professional experience |
System and Context Attributes
Attribute | Type | Default | Description |
---|---|---|---|
system_prompt | str | None | None | Custom system prompt for the agent |
reflection | bool | False | Reflection capabilities |
compress_context | bool | False | Enable context compression |
Tool and Execution Attributes
Attribute | Type | Default | Description |
---|---|---|---|
show_tool_calls | bool | True | Display tool call information |
tool_call_limit | int | 5 | Maximum number of tool calls per execution |
tool_call_count | int | 0 | Current tool call count (read-only) |
enable_thinking_tool | bool | False | Enable thinking/reasoning capabilities |
enable_reasoning_tool | bool | False | Enable advanced reasoning (requires thinking) |
enable_reasoning_tool
requires enable_thinking_tool
to be True
. Setting reasoning without thinking will raise a ValueError
.
Memory and Storage Attributes
Attribute | Type | Default | Description |
---|---|---|---|
memory | Memory | None | None | Memory management system |
feed_tool_call_results | bool | False | Include tool results in memory |
Safety and Reliability Attributes
Attribute | Type | Default | Description |
---|---|---|---|
user_policy | Policy | None | None | Safety policy for user input validation |
agent_policy | Policy | None | None | Safety policy for agent output validation |
reliability_layer | Any | None | None | Reliability and validation layer |
Canvas and External Integration Attributes
Attribute | Type | Default | Description |
---|---|---|---|
canvas | Canvas | None | None | Canvas for persistent text storage |
Adding a Memory
Memory capabilities allow your agent to maintain context across conversations, learn from interactions, and provide personalized responses. The memory system supports multiple storage backends and various memory types.Memory System Overview
The memory system in Upsonic provides three main types of memory:- Full Session Memory: Stores complete conversation history
- Summary Memory: Maintains condensed summaries of conversations
- User Analysis Memory: Builds user profiles and preferences
Setting Up Memory with SQLite
Memory Configuration Options
Parameter | Type | Default | Description |
---|---|---|---|
storage | Storage | Required | Storage backend (SQLite, PostgreSQL, MongoDB, etc.) |
session_id | str | None | None | Unique session identifier |
user_id | str | None | None | User identifier for profile building |
full_session_memory | bool | False | Enable complete conversation storage |
summary_memory | bool | False | Enable conversation summarization |
user_analysis_memory | bool | False | Enable user profile analysis |
num_last_messages | int | None | None | Limit conversation history to last N messages |
user_memory_mode | Literal['update', 'replace'] | 'update' | How to update user profiles |
Using Memory in Task Execution
When memory is enabled, the agent automatically:- Retrieves relevant context from previous conversations
- Updates user profiles based on interactions
- Maintains conversation summaries for long-term context
- Feeds tool call results into memory (if enabled)
Memory Management Methods
The agent provides methods to manage memory:Adding Thinking Tool
Thinking Tool capabilities enable the agent to think through problems step-by-step, analyze its own reasoning, and provide more thoughtful responses. This is particularly useful for complex problem-solving tasks.Enabling Thinking Tool
Thinking Tool is controlled by theenable_thinking_tool
parameter:
How Thinking Tool Works
When Thinking Tool is enabled, the agent:- Analyzes the problem before attempting to solve it
- Breaks down complex tasks into manageable steps
- Evaluates its own reasoning and adjusts if needed
- Provides detailed explanations of its thought process
Thinking Tool Configuration
You can control Thinking Tool at both the agent and task level:Thinking Tool Use Cases
Thinking Tool is particularly valuable for:- Financial calculations and modeling
- Risk assessment and compliance analysis
- Multi-step loan processing workflows
- Regulatory compliance verification
- Investment strategy planning
Adding Reasoning
Reasoning capabilities build upon Thinking Tool to provide even more sophisticated problem-solving abilities. Reasoning enables the agent to use advanced logical analysis and structured thinking approaches.Enabling Reasoning
Reasoning requires bothenable_thinking_tool
and enable_reasoning_tool
to be True
:
enable_reasoning_tool
cannot be True
if enable_thinking_tool
is False
. This will raise a ValueError
.
Reasoning vs. Thinking Tool
Feature | Thinking Tool (enable_thinking_tool ) | Reasoning (enable_reasoning_tool ) |
---|---|---|
Purpose | Basic step-by-step financial analysis | Advanced risk and compliance analysis |
Complexity | Simple to moderate financial problems | Complex, multi-faceted banking scenarios |
Output | Clear financial explanations | Structured analysis with regulatory recommendations |
Use Cases | Interest calculations, basic risk assessment | Strategic banking planning, complex compliance analysis |
Reasoning Configuration
Reasoning can be configured at multiple levels:Advanced Reasoning Use Cases
Reasoning is ideal for:- Strategic banking and fintech analysis
- Complex financial data interpretation
- Multi-variable risk assessment
- Regulatory compliance and risk mitigation
- Portfolio optimization and investment strategies
Reasoning Output Structure
When reasoning is enabled, the agent provides:- Financial Problem Decomposition: Breaking complex banking scenarios into components
- Risk Analysis: Step-by-step risk assessment and logical reasoning
- Regulatory Evidence Evaluation: Assessing compliance requirements and financial data
- Financial Synthesis: Combining insights into coherent banking recommendations
- Actionable Recommendations: Specific next steps for implementation and compliance
Performance Considerations
Warning: Reasoning capabilities consume more tokens and processing time than basic Thinking Tool. Monitor your usage and costs when using reasoning for production applications.Complete Example: Advanced Agent Configuration
Here’s a comprehensive example showing how to create a fully-featured agent with all capabilities:Best Practices
- Start Simple: Begin with basic configuration and add features as needed for your banking use case
- Monitor Performance: Use debug mode to understand token usage and costs in financial applications
- Memory Management: Choose appropriate memory settings for customer relationship management and compliance tracking
- Safety First: Always implement appropriate safety policies for financial data and regulatory compliance
- Error Handling: Configure retry settings based on your reliability requirements for critical banking operations
- Resource Management: Be mindful of token consumption with reasoning capabilities in risk assessment scenarios
- Regulatory Compliance: Ensure all AI outputs meet banking regulations and compliance requirements
- Data Security: Implement proper data encryption and access controls for sensitive financial information