Files
mai-bot/agentlite/examples/single_agent.py
2026-04-03 22:15:53 +08:00

43 lines
1.0 KiB
Python

"""Example: Single Agent Usage
This example demonstrates basic usage of the AgentLite Agent class.
"""
import asyncio
import os
from agentlite import Agent, OpenAIProvider
async def main():
"""Run the single agent example."""
# Create provider
provider = OpenAIProvider(
api_key=os.getenv("OPENAI_API_KEY", "your-api-key"),
model="gpt-4o-mini",
)
# Create agent
agent = Agent(
provider=provider,
system_prompt="You are a helpful assistant. Be concise.",
)
# Run conversation
print("User: What is Python?")
response = await agent.run("What is Python?")
print(f"Agent: {response}\n")
print("User: What are its main features?")
response = await agent.run("What are its main features?")
print(f"Agent: {response}\n")
# Show conversation history
print("--- Conversation History ---")
for msg in agent.history:
print(f"{msg.role}: {msg.extract_text()[:100]}...")
if __name__ == "__main__":
asyncio.run(main())