from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.tools.openai_dalle_image_generation import OpenAIDALLEImageGenerationTool
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
# Configure DallEAPIWrapper for Lumenfall
dalle = DallEAPIWrapper(
model="gemini-3-pro-image",
openai_api_key="lmnfl_your_api_key",
openai_api_base="https://api.lumenfall.ai/openai/v1"
)
# Create the image generation tool
image_tool = OpenAIDALLEImageGenerationTool(api_wrapper=dalle)
# Create the agent
llm = ChatOpenAI(model="gpt-4o")
tools = [image_tool]
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant that can generate images."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Run the agent
result = executor.invoke({
"input": "Create an image of a futuristic city with flying cars"
})
print(result["output"])