Foundry SDKs and Connectors
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
Lesson: Foundry SDKs and Connectors in Generative AI
Introduction: Bridging the Gap Between Models and Data
In the modern landscape of software development, the transition from simple prompt engineering to functional, agentic generative applications relies heavily on the infrastructure connecting your models to your data. While large language models (LLMs) are impressive in their ability to process information, they are inherently "stateless" and lack access to the specific, private, or real-time data residing in your enterprise systems. This is where Foundry SDKs and Connectors enter the picture. They serve as the critical middleware that allows your applications to move beyond basic text generation and into the realm of complex, data-driven decision-making.
Understanding these tools is essential because the true value of generative AI is not in the model itself, but in how effectively that model can interact with your existing ecosystem. Without a structured way to fetch, transform, and feed data into an LLM—and subsequently act upon its outputs—your application remains a siloed experiment. By mastering Foundry SDKs and connectors, you move from building prototypes to building reliable, scalable systems that can query databases, interact with APIs, and execute workflows based on intelligent insights. This lesson will guide you through the architecture, implementation, and best practices of using these components to build high-functioning agentic solutions.
1. The Architecture of Connectors and SDKs
To understand why we need these tools, it is helpful to visualize the generative application stack. At the top, you have the user interface and the LLM. At the bottom, you have your operational databases, CRMs, cloud storage, and legacy internal systems. The Foundry SDKs act as the "glue" that translates the high-level intent of an LLM into structured requests that your systems can understand.
What are Connectors?
Connectors are pre-built or custom-developed modules designed to establish a secure, reliable link between your application environment and an external data source. They handle the "heavy lifting" of authentication, data pagination, rate limiting, and schema mapping. In an agentic workflow, a connector isn't just a passive data fetcher; it is an interface that allows the agent to "read" the state of a system and "write" changes back to it.
What is the Foundry SDK?
The Foundry SDK serves as the developer's primary toolkit for interacting with the orchestration layer. It provides the methods and objects necessary to instantiate agents, define tools, manage conversation history, and trigger long-running processes. When you use an SDK, you are essentially providing your application with a standard vocabulary to talk to the AI infrastructure, regardless of which underlying model (such as GPT-4, Claude, or Llama) you happen to be using at that moment.
Callout: The Distinction Between SDKs and Connectors It is common to confuse these two, but they serve distinct functions. Think of the SDK as the "Control Panel" of your application—it provides the functions to run the logic, maintain state, and handle errors. Think of the Connector as the "Plug" that allows the control panel to access external hardware. You use the SDK to write the application, but you use the Connectors to ensure that the application has the fuel (data) it needs to function.
2. Implementing Connectors: A Step-by-Step Approach
Building a connector involves more than just writing a database query. You must ensure that the data being pulled is relevant to the LLM's context window and that the connection remains secure.
Step 1: Defining the Interface
Before writing code, define what the agent needs to know. If you are building a customer support agent, the agent needs to know the user's order history, their current account status, and any open support tickets. You should not dump an entire database into the LLM; instead, you create a connector method that retrieves only the necessary fields.
Step 2: Authentication and Security
Security is the most critical aspect of connector development. Never hardcode credentials. Use environment variables or a dedicated secret management service. When connecting to a production database, always use a read-only service account to ensure that the agent cannot accidentally delete or modify data unless explicitly permitted by your design.
Step 3: Data Transformation
LLMs prefer clean, structured text (like JSON or Markdown). Raw database outputs are often cluttered with internal IDs or metadata that the agent doesn't need. Your connector should include a transformation layer that cleans the data and presents it in a context-aware format.
Practical Example: Building a Simple SQL Connector
Below is a conceptual implementation of a connector that fetches user data from a relational database for an agent to process.
import os
import sqlite3
class UserDataConnector:
def __init__(self, db_path):
self.db_path = db_path
def get_user_summary(self, user_id):
"""Fetches essential user data for the agent."""
try:
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
query = "SELECT name, email, subscription_tier FROM users WHERE id = ?"
cursor.execute(query, (user_id,))
result = cursor.fetchone()
if result:
return {
"name": result[0],
"email": result[1],
"tier": result[2]
}
return None
except Exception as e:
print(f"Error connecting to database: {e}")
return None
finally:
conn.close()
# Usage in the application
connector = UserDataConnector("enterprise_data.db")
user_info = connector.get_user_summary(101)
In this example, the connector acts as a filter. Instead of giving the agent access to the entire users table, we expose a specific get_user_summary function. This limits the "blast radius" of what the agent can see, which is a key security practice.
3. Utilizing Foundry SDKs for Agentic Workflows
Once your connectors are in place, the Foundry SDK allows you to orchestrate the agent's behavior. An agentic workflow usually follows a loop:
- Observation: The agent looks at the current state.
- Thought: The agent decides which tool to use.
- Action: The agent calls the connector tool.
- Result: The agent observes the output and repeats or responds to the user.
Defining Tools in the SDK
The SDK allows you to wrap your connector methods as "Tools." These tools are then registered with the LLM, giving it the ability to "call" them when it determines that external information is required.
Example: Registering a Tool with the SDK
This snippet demonstrates how you might register a custom tool to be used by an agent orchestration framework.
from my_foundry_sdk import Agent, Tool
# Instantiate the agent
support_agent = Agent(name="CustomerSupportBot")
# Define the tool registration
@support_agent.tool(description="Fetches user account status from the database")
def fetch_account_status(user_id: str):
connector = UserDataConnector("enterprise_data.db")
data = connector.get_user_summary(user_id)
return f"User details: {data}"
# The agent now has the capability to 'call' this function
# when the user asks, "What is my subscription status?"
Note: Always provide a clear, descriptive docstring or description for your tools. The LLM relies on these descriptions to decide when to use the tool. If the description is vague, the agent will struggle to determine if it should call the function or try to answer from its own internal knowledge.
4. Best Practices for Production Systems
Building for production requires a different mindset than building for a demo. When deploying agentic applications, consider the following standards.
Error Handling and Retries
Network calls to APIs or databases will fail. Your connectors should implement robust error handling. If a connector fails to reach the database, the agent should not crash; instead, it should inform the user that it is currently unable to access that specific information. Use exponential backoff strategies for API connectors to avoid overwhelming external systems during periods of high traffic.
Observability and Logging
In a standard application, you log the inputs and outputs of your functions. In an agentic application, you must log the thought process. Use the Foundry SDK's built-in logging hooks to track:
- Which tool the agent decided to call.
- The raw data returned by the connector.
- The final response generated by the LLM.
- The latency of each step.
Human-in-the-Loop (HITL)
For any action that modifies data (e.g., updating a support ticket, issuing a refund), you should implement a HITL check. The SDK should allow the agent to propose an action, pause, and wait for a human supervisor to click "Approve" before the connector executes the write operation. Never give an autonomous agent unchecked write access to critical business databases.
5. Comparison: SDK-Integrated Connectors vs. Custom API Wrappers
When deciding how to connect your data, you might wonder whether to use an existing SDK or build a custom wrapper. The following table highlights the differences.
| Feature | Foundry SDK Integrated | Custom API Wrapper |
|---|---|---|
| Maintenance | Low (Updates managed by provider) | High (Manual updates required) |
| Security | Built-in (OAuth, Secret Management) | Manual (Requires custom implementation) |
| Performance | Optimized for agentic latency | Variable |
| Flexibility | High (Standardized tool interface) | Very High (Can do anything) |
| Integration | Seamless with agentic lifecycle | Often requires extra parsing logic |
6. Common Pitfalls and How to Avoid Them
Pitfall 1: Over-fetching Data
A common mistake is returning too much information from the connector. If your database query returns 50 columns of data but the agent only needs the user's name and subscription status, you are wasting tokens and potentially confusing the agent.
- Solution: Write your connector queries to select only the specific columns required for the task.
Pitfall 2: Ignoring Rate Limits
If your agent is designed to loop through a list of items and call a connector for each one, you might inadvertently trigger a rate limit on your database or API.
- Solution: Implement internal throttling in your connector logic to ensure you never exceed the allowed number of requests per second.
Pitfall 3: The "Infinite Loop" Problem
Sometimes, an agent might get stuck in a loop, repeatedly calling the same tool with the same inputs because it doesn't understand why the result isn't helping it solve the user's problem.
- Solution: Use the SDK to set a "max tool calls" limit per request. If the agent hits this limit, force it to stop and ask the user for clarification.
Callout: Agentic vs. Non-Agentic Flows It is important to remember that not every application needs to be agentic. A non-agentic flow is one where the data is fetched, processed, and then sent to the LLM in a single pass. An agentic flow is one where the LLM is given the autonomy to fetch the data itself. Use agentic flows only when the path to the answer requires multiple steps or conditional logic.
7. Advanced Implementation: Managing State Across Connectors
In complex applications, you may have multiple connectors interacting with different systems. Managing the state of these interactions is vital. The Foundry SDK often provides a "Memory" or "Session" object that persists across the conversation. When you fetch data via a connector, store the relevant parts of that data in the session memory. This prevents the agent from having to re-fetch the same data multiple times during a single interaction.
Example: Maintaining Session State
# Using the SDK's session management
agent.session.set("user_context", {
"user_id": 101,
"last_access": "2023-10-27"
})
# Later in the conversation, the agent can check the memory
# before deciding to call the connector again.
if not agent.session.get("user_context"):
# Call the connector only if context is missing
data = connector.get_user_summary(101)
agent.session.set("user_context", data)
By keeping the session state clean, you drastically improve the agent's performance and reduce the costs associated with redundant API calls. This is a hallmark of a well-architected generative application.
8. Security and Governance: The "Human-in-the-Loop" Mandate
We touched on this briefly, but it deserves deep focus. When we talk about "Agentic Solutions," we are often talking about systems that can perform work. In an enterprise environment, "work" often involves modifying business records.
Defining Governance Policies
- Read-Only by Default: Connectors should be read-only unless a specific, audited write-permission is granted.
- Scope Limitation: Use scoped API keys. If a connector only needs to read support tickets, ensure the API key it uses does not have access to billing or HR data.
- Audit Trails: Every action performed by an agent via a connector should be logged with the agent's ID, the user's intent, the tool called, and the outcome. This is essential for compliance and debugging.
Implementing a Approval Workflow
If the agent determines that a write action is necessary, it should return a structured response indicating the intent. Your application layer should intercept this intent, present it to a human user in a dashboard, and only execute the connector's write method after manual confirmation.
# Conceptual logic for a write-action approval
def handle_agent_action(action_name, params):
if action_name == "update_billing":
# Do not execute directly
request_human_approval(action_name, params)
else:
# Execute directly for non-sensitive actions
execute_tool(action_name, params)
9. Future-Proofing Your Connectors
Technology moves fast, and the LLMs we use today will be replaced by more capable models tomorrow. How do you ensure your connector infrastructure survives these transitions?
- Standardize Your Data Formats: Regardless of the model, aim to output data as JSON. JSON is the universal language of modern AI APIs.
- Decouple Logic from Frameworks: Keep your connector code as pure Python (or your language of choice) as possible. Do not tie your business logic directly to the SDK’s internals. If you ever need to switch frameworks, you should only have to rewrite the "glue" code, not the underlying data-fetching logic.
- Version Your Tools: If you update a connector and change its output format, you might break your agents. Use versioning for your tools (e.g.,
fetch_user_v1,fetch_user_v2) so you can migrate agents gradually.
10. Summary and Key Takeaways
Building generative applications is a journey from simple prompting to building intelligent agents that live within your data ecosystem. The Foundry SDKs and Connectors are the foundation of this journey. They provide the structure, security, and connectivity required to turn a generic model into a specialized assistant.
Key Takeaways
- Connectors are the bridge: They allow LLMs to access private, real-time data, transforming static models into dynamic, context-aware agents.
- SDKs provide the control layer: Use the SDK to manage the agent's lifecycle, tool registration, and session memory. This keeps your code organized and maintainable.
- Security is non-negotiable: Implement read-only access by default, use environment variables for secrets, and always require human approval for actions that modify business state.
- Efficiency matters: Avoid over-fetching data. Keep your connector queries focused on the specific fields required by the agent to reduce token usage and improve response times.
- Observability is mandatory: Log not just the errors, but the agent's "thought process." Understanding why an agent chose a specific tool is as important as knowing whether the tool succeeded.
- Plan for change: Decouple your business logic from the specific SDK or LLM framework you are currently using. By keeping your code modular, you ensure that your investment in connector development remains valuable as the technology landscape evolves.
- Design for humans: Even in an autonomous agentic system, the human should remain the ultimate authority. Use "Human-in-the-Loop" patterns for any high-stakes decisions to maintain safety and trust.
By following these principles, you will be well-equipped to build sophisticated, reliable, and secure generative applications that deliver genuine value to your users. The goal is not just to build an agent that can talk, but to build an agent that can act, learn, and operate within the constraints and realities of your business environment.
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons