Build your Agent
Install the SDK
Set up your Python project, ideally with a virtual environment, and install the necessary libraries:
pip install lynkr langchain_openai langgraph python-dotenv
Initialize the Client
Ensure you have a .env file in your working directory with your API keys:
LYNKR_API_KEY=your_lynkr_api_key
RESEND_API_KEY=your_resend_api_key
OPENAI_API_KEY=your_openai_api_key
Then, initialize the Lynkr client:
import os
from dotenv import load_dotenv
from lynkr import LynkrClient
load_dotenv()
lynkr_client = LynkrClient(api_key=os.getenv("LYNKR_API_KEY"))
Add Service Credentials (Optional)
If the service you’re using (e.g., Resend) requires authentication, add the credentials to your Lynkr client:
lynkr_client.add_key(
service="resend",
header="x-api-key",
api_key=os.getenv("RESEND_API_KEY")
)
Set Up LangChain and LangGraph Integration
Set up the integration with OpenAI and LangChain for advanced orchestration:
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
from langgraph.prebuilt import create_react_agent
# Retrieve Lynkr tools
tools = lynkr_client.langchain_tools()
# Initialize OpenAI model
model = ChatOpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
model="o4-mini",
temperature=1
)
# Create ReAct agent with Lynkr tools
agent = create_react_agent(
model=model,
tools=tools
)
Usage Example
Use the agent to interactively fulfill user requests using Lynkr:
prompt = """
You are LynkrGPT, an agent that fulfills user requests by orchestrating two tools:
IMPORTANT: Always start by invoking the get_schema tool with the user request unless already obtained.
1. get_schema(request_string: str)
- Example: "create an opportunity"
2. execute_schema(schema_data: dict, ref_id: str, service: str)
Always:
- Verify if you already have the schema; do not request again if you do.
- Use execute_schema after filling in required details from the schema_example.
- Respond with confirmation or request clarification if needed.
EXAMPLE FLOW:
1. User: "I want to create a contact in HubSpot"
2. get_schema("create a contact")
3. Obtain schema_example, ref_id, and service
4. Ask user for required details
5. Execute filled schema_example
6. Confirm success to user
Begin!
"""
response = agent.invoke("I want to send an email")
print(response)
Next Steps
Your Lynkr client is now ready to use. Proceed with:
-
Exploring additional Lynkr tools
-
Learning more about advanced usage scenarios
Last updated on