Welcome to your first TFrameX example! This demonstrates the most basic usage of TFrameX with a simple agent that greets users.
- How to create a TFrameX application
- How to define a simple agent
- How to run agents and get responses
- Basic TFrameX concepts and structure
hello-world/
├── README.md # This guide
├── requirements.txt # Python dependencies
├── .env.example # Environment template
├── main.py # Main application
├── config/
│ └── agents.py # Agent definitions
└── docs/
├── setup.md # Setup instructions
└── usage.md # Usage examples
pip install -r requirements.txtcp .env.example .env
# Edit .env with your LLM settingspython main.py# Required: LLM Configuration
OPENAI_API_KEY=your_api_key_here
OPENAI_API_BASE=https://api.openai.com/v1
OPENAI_MODEL_NAME=gpt-3.5-turbo
# Optional: Application Settings
APP_NAME=Hello World TFrameX
LOG_LEVEL=INFOOPENAI_API_BASE=http://localhost:11434/v1
OPENAI_API_KEY=ollama
OPENAI_MODEL_NAME=llama3from tframex import TFrameXApp, OpenAIChatLLM, Message
# Create LLM instance
llm = OpenAIChatLLM(
model_name=os.getenv("OPENAI_MODEL_NAME", "gpt-3.5-turbo"),
api_base_url=os.getenv("OPENAI_API_BASE"),
api_key=os.getenv("OPENAI_API_KEY")
)
# Initialize TFrameX app
app = TFrameXApp(default_llm=llm)@app.agent(
name="GreeterAgent",
description="A friendly greeting agent",
system_prompt="You are a friendly greeter. Greet the user warmly and ask how you can help them today."
)
async def greeter_agent():
pass # Logic handled by TFrameX LLMAgentasync with app.run_context() as rt:
response = await rt.call_agent(
"GreeterAgent",
Message(role="user", content="Hello!")
)
print(f"Agent: {response.content}")The example includes an interactive mode where you can chat with the agent:
async with app.run_context() as rt:
await rt.interactive_chat(default_agent_name="GreeterAgent")- Central application instance
- Manages agents, tools, and configuration
- Provides runtime contexts
- Autonomous entities powered by LLMs
- Defined using decorators (
@app.agent) - Can have custom system prompts and behaviors
- Execution environment for agents
- Manages LLM connections and cleanup
- Used with
async with app.run_context()
- Standard communication format
- Contains role (user/assistant/tool) and content
- Used for all agent interactions
After running this example, try:
- Modify the system prompt to change the agent's personality
- Add template variables to the system prompt
- Experiment with different LLM models
- Move to the next example: Simple Agent
Error: "No module named 'tframex'"
pip install tframexError: "OpenAI API key not found"
- Check your
.envfile hasOPENAI_API_KEYset - Ensure the
.envfile is in the same directory asmain.py
Error: "Connection failed"
- Verify your
OPENAI_API_BASEURL is correct - For local models, ensure the server is running
- Documentation: TFrameX Docs
- Discord: Join our Discord
- Issues: GitHub Issues
This example is provided under the MIT License.