Integrating with Popular AI Frameworks
The Fiscus SDK integrates seamlessly with popular AI frameworks, allowing developers to harness large language models and AI agents for robust API orchestration. This section explores how to use ai_execute
within frameworks such as LangChain, OpenAI Function Calling, CrewAI, and even custom AI agent setups.
LangChain Integration
With LangChain, you can integrate Fiscus to enable agents to interact dynamically with multiple APIs. This setup allows agents to trigger complex workflows through natural language prompts and execute tasks using ai_execute
.
Key Benefits:
- Dynamic API Interaction: LangChain agents can route multi-API workflows via
ai_execute
. - Flexible Integration: Use natural language to interact with various APIs without hardcoding each request.
- Enhanced AI Reasoning: Combine LangChain’s reasoning capabilities with Fiscus’s API management.
- Python
Example: Using Fiscus with LangChain
Scenario: An agent is tasked to send an email using gmail via ai_execute
.
from fiscus import FiscusClient
from langchain.agents import initialize_agent, Tool
from langchain.llms import OpenAI
# Initialize Fiscus client
client = FiscusClient(api_key='YOUR_FISCUS_API_KEY', user_id='USER_ID')
# Define a Fiscus tool for LangChain
def fiscus_tool(query):
response = client.ai_execute(input=query)
return response.result
# Create LangChain tool
fiscus_langchain_tool = Tool(
name="FiscusTool",
func=fiscus_tool,
description="Handles API operations via Fiscus."
)
# Initialize OpenAI language model
llm = OpenAI(api_key='YOUR_OPENAI_API_KEY')
# Initialize the agent with Fiscus tool and LangChain
agent = initialize_agent(
tools=[fiscus_langchain_tool],
llm=llm,
agent='zero-shot-react-description',
verbose=True
)
# Send an email using the agent
result = agent.run("Send an email to alice@example.com about tomorrow's meeting.")
print(result)
How It Works:
- Fiscus Tool: The fiscus_tool allows LangChain to convert natural language into API calls.
- Dynamic API Routing: The agent uses
ai_execute
to route tasks intelligently to the correct API. - Simplified Workflow: The agent seamlessly executes tasks without manual API configurations.
Using Fiscus with OpenAI Function Calling
OpenAI’s Function Calling feature allows language models to perform structured tasks, such as interacting with APIs. By combining Fiscus with OpenAI’s function calling, developers can manage complex API workflows within an AI-powered environment.
Key Benefits:
- Automated API Routing: Direct tasks to the relevant API based on user queries.
- Effortless Setup: Use OpenAI’s function calling to trigger
ai_execute
, facilitating robust API interactions. - Customizable Execution: Define operations and parameters tailored to specific application requirements.
Example: OpenAI Function Calling with Fiscus
Scenario: Using OpenAI’s function calling to send an email using ai_execute
.
import openai
import json
from fiscus import FiscusClient
# Initialize Fiscus client
client = FiscusClient(api_key='YOUR_FISCUS_API_KEY', user_id='USER_ID')
# Set OpenAI API key
openai.api_key = "YOUR_OPENAI_API_KEY"
# Define function to execute Fiscus operations
def execute_fiscus_operation(connector, operation, params):
response = client.ai_execute(input=f"Perform {operation} via {connector}")
return response.result
# Define OpenAI function
functions = [
{
"name": "execute_fiscus_operation",
"description": "Executes operations via Fiscus",
"parameters": {
"type": "object",
"properties": {
"connector": {"type": "string"},
"operation": {"type": "string"},
"params": {"type": "object"}
},
"required": ["connector", "operation", "params"]
}
}
]
# OpenAI ChatCompletion request
response = openai.ChatCompletion.create(
model="gpt-4-0613",
messages=[{"role": "user", "content": "Send an email to user@example.com with the subject 'Meeting Reminder'"}],
functions=functions,
function_call={"name": "execute_fiscus_operation"}
)
# Parse function call response
function_call = response["choices"][0]["message"]["function_call"]
function_args = json.loads(function_call["arguments"])
# Execute the function via Fiscus
result = execute_fiscus_operation(**function_args)
print(result)
How It Works:
- Function Call Setup: OpenAI uses function calling to determine the necessary API action.
- Fiscus Execution:
ai_execute
performs the API call, offloading task routing to Fiscus. - Dynamic Task Handling: The agent automatically identifies and routes tasks to the appropriate API.
CrewAI with Fiscus
CrewAI facilitates task management across multiple agents. By integrating Fiscus with CrewAI, you can orchestrate complex workflows that span multiple APIs and tasks.
Key Benefits:
- Multi-Agent Collaboration: Coordinate tasks across agents, each performing specialized API calls via
ai_execute
. - Task-Specific API Handling: Agents independently manage API interactions for specific tasks.
- Scalable Architecture: Add agents and tasks without increasing API handling complexity.
Example: CrewAI with Fiscus
Scenario: Create a calendar event and send notifications using CrewAI and Fiscus to interact with Google Calendar and Slack.
from fiscus import FiscusClient
from crewai import Agent, Task, Crew
from langchain.llms import OpenAI
# Initialize Fiscus client
client = FiscusClient(api_key='YOUR_FISCUS_API_KEY', user_id='USER_ID')
# Initialize OpenAI LLM
language_model = OpenAI(api_key="YOUR_OPENAI_API_KEY")
# Define a custom Fiscus Agent
class FiscusAgent(Agent):
def execute(self, task):
user_input = task.description
response = client.ai_execute(input=user_input)
return response.result
# Create Fiscus agent
agent = FiscusAgent(name="FiscusAgent")
# Define task to create a calendar event
task = Task(
description="Create a calendar event for next Monday at 10 AM.",
agent=agent
)
# Initialize Crew with Fiscus agent
crew = Crew(agents=[agent], tasks=[task])
# Run the task
result = crew.run()
print(result)
How It Works:
- Fiscus Agent: The agent uses
ai_execute
to handle task routing to the correct API. - Multi-Agent System: Agents collaborate within CrewAI, each independently managing API interactions.
- Scalability: Tasks can be added or modified without increasing API integration complexity.
Custom AI Agent Integrations
Fiscus provides flexibility for custom AI agents, enabling them to use ai_execute
for API routing across diverse workflows. This flexibility supports proprietary models and specialized frameworks, facilitating seamless API orchestration.
Key Benefits:
- Customizable Routing: Create agents that intelligently manage API calls, using
ai_execute
to handle any workflow. - Dynamic Execution: Agents can adjust API calls based on input, managing complex workflows with ease.
- Hook Customization: Utilize pre- and post-execution hooks to track and modify API behavior as needed.
Example: Custom AI Agent with Fiscus
Scenario: A custom AI agent integrates with a CRM and sends follow-up emails after updating contacts.
from fiscus import FiscusClient
# Initialize Fiscus client
client = FiscusClient(api_key='YOUR_FISCUS_API_KEY', user_id='USER_ID')
# Custom agent logic for multi-API execution
def custom_agent_logic(input):
response = client.ai_execute(input=input)
return response.result
# Execute multi-API task
result = custom_agent_logic("Update contact in CRM and send a follow-up email")
print(result)
How It Works:
- Custom Agent Logic: The agent uses
ai_execute
to interpret the input and perform API actions. - Flexible API Execution: With
ai_execute
, the agent can interact with any API, simplifying API management. - Easily Scalable: Additional tasks can be incorporated without increasing code complexity, as Fiscus handles the API routing.
Conclusion
Fiscus integrates seamlessly with frameworks like LangChain, OpenAI Function Calling, and CrewAI, providing a robust platform for multi-API orchestration. By utilizing ai_execute
, developers can build complex, AI-driven workflows that handle API interactions dynamically, reducing manual configuration and enhancing the flexibility of AI agent development.