Skip to main content
Version: Next

Module

The Module is a container that wraps framework-specific agents and registers them with the Runtime.

Overview​

What is a Module?​

A Module:

  • Wraps framework-specific agents
  • Creates Agent Kernel Agent instances
  • Creates appropriate Runners
  • Registers agents with the Runtime

Framework Modules​

OpenAIModule​

from agentkernel.openai import OpenAIModule
from agents import Agent as OpenAIAgent

agent = OpenAIAgent(name="assistant", instructions="...")
OpenAIModule([agent])

CrewAIModule​

from agentkernel.crewai import CrewAIModule
from crewai import Agent as CrewAgent

agent = CrewAgent(role="assistant", goal="...", backstory="...")
CrewAIModule([agent])

LangGraphModule​

from agentkernel.langgraph import LangGraphModule
from langgraph.graph import StateGraph

graph = StateGraph(...).compile()
graph.name = "assistant"
LangGraphModule([graph])

GoogleADKModule​

from agentkernel.adk import GoogleADKModule
from adk import Agent as ADKAgent

agent = ADKAgent(name="assistant", model="gemini-2.0-flash-exp", ...)
GoogleADKModule([agent])

Module Lifecycle​

Creating Modules​

Single Agent​

from agentkernel.crewai import CrewAIModule
from crewai import Agent

agent = Agent(role="assistant", ...)
CrewAIModule([agent])

Multiple Agents​

from agentkernel.crewai import CrewAIModule
from crewai import Agent

agent1 = Agent(role="researcher", ...)
agent2 = Agent(role="writer", ...)
agent3 = Agent(role="reviewer", ...)

CrewAIModule([agent1, agent2, agent3])

Module Configuration​

Some modules accept configuration:

from agentkernel.openai import OpenAIModule

OpenAIModule(
agents=[agent1, agent2],
model_override="gpt-4", # Override default model
)

Native run options​

run_options(agent, [factory], **options) declares the framework's own per-run options for one agent, in the framework's own types, and is chained like pre_hook / post_hook:

from agents import Agent, RunConfig

agent = Agent(name="assistant", instructions="...")

OpenAIModule([agent]).run_options(
agent,
max_turns=25,
hooks=ProgressHooks(),
run_config=RunConfig(call_model_input_filter=trim_history),
).pre_hook(agent, [RAGHook()])

Every keyword is a keyword argument of that framework's native run call (LangGraph's config, ADK's plugins and run_config, Pydantic AI's usage_limits, Microsoft Agent Framework's options, CrewAI's step_callback, smolagents' max_steps). Repeated calls merge, the later call winning per key. A key the adapter populates itself (session, context, input, ...) raises ValueError at declaration. See Runner → Per-agent native run options for the merge rule and the per-framework table.

A callable given positionally before the keywords computes options per run. It is called as factory(agent, session, requests) on every run, sync or async, and its mapping is merged over the static keywords, a factory key winning. One factory per agent, a later call replacing it; a non-callable raises TypeError at declaration. The factory is accepted only positionally (the agent keeps its keyword form, as with pre_hook / post_hook), so a native option named factory is still declared as a keyword.

def options_for(agent, session, requests):
return {"max_turns": 10} if session.id.startswith("guest") else {}

OpenAIModule([agent]).run_options(agent, options_for, max_turns=25, hooks=ProgressHooks())

Best Practices​

One Module Per Application​

Typically, create one module per application. In a use case of having agents of multiple agentic frameworks, you can instentiate multiple modules. However, please note that hands offs are only possible within the assigned module. If you need to talk to agents defined in other modules they should be exposed via A2A.

# my_agent.py
from agentkernel.crewai import CrewAIModule
from crewai import Agent

agents = [agent1, agent2, agent3]
CrewAIModule(agents)

if __name__ == "__main__":
from agentkernel.cli import CLI
CLI.main()

Summary​

  • Modules wrap framework agents
  • Create AK Agents and Runners
  • Automatically register with Runtime
  • Each framework has its own Module class

Next Steps​

Ready to Ship Your
First Agent?

Free, open-source, Apache 2.0. No licensing costs, no vendor lock-in. Join hundreds of developers building production AI agents with Agent Kernel.

Agent Kernel
Ask Agent Kernel