### Install litecrew with Provider Support Source: https://github.com/menonpg/litecrew/blob/main/README.md Install litecrew with support for specific AI providers like OpenAI or Anthropic, or install all supported providers. ```bash pip install litecrew[openai] # OpenAI support pip install litecrew[anthropic] # Anthropic support pip install litecrew[all] # Everything including memory ``` -------------------------------- ### Install litecrew using pip Source: https://github.com/menonpg/litecrew/blob/main/README.md Install the litecrew library using pip. This is the first step before using any of its features. ```bash pip install litecrew ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/menonpg/litecrew/blob/main/README.md Install the development dependencies for litecrew, which include testing tools like pytest. ```bash pip install litecrew[dev] ``` -------------------------------- ### Create a Basic Agent Source: https://github.com/menonpg/litecrew/blob/main/README.md Instantiate a basic agent with a name, model, and system prompt. You can then use the agent to process text. ```python from litecrew import Agent agent = Agent( name="assistant", model="gpt-4o-mini", # or "claude-3-5-sonnet-20241022" system="You are a helpful assistant." ) response = agent("What is the capital of France?") print(response) print(agent.tokens) # {"in": 23, "out": 15} ``` -------------------------------- ### Mix Cloud and Local Models Source: https://github.com/menonpg/litecrew/blob/main/README.md Combine local models for cost-effectiveness and cloud models for quality by specifying different models for different agents. ```python # Use local for research (free), cloud for final output (quality) researcher = Agent("researcher", model="llama3.2") # Local via Ollama writer = Agent("writer", model="gpt-4o") # Cloud via OpenAI ``` -------------------------------- ### Configure litecrew for Local Models via Environment Variables Source: https://github.com/menonpg/litecrew/blob/main/README.md Alternatively, configure litecrew to use local models by setting environment variables for the API base URL and key. ```bash export OPENAI_BASE_URL="http://localhost:11434/v1" export OPENAI_API_KEY="ollama" ``` -------------------------------- ### Run Tests Source: https://github.com/menonpg/litecrew/blob/main/README.md Execute the test suite for litecrew using pytest. ```bash pytest tests/ ``` -------------------------------- ### Sequential Agent Handoff Source: https://github.com/menonpg/litecrew/blob/main/README.md Define a sequence of agents that pass their output to the next agent in the pipeline. Useful for multi-step tasks. ```python from litecrew import Agent, sequential researcher = Agent("researcher", model="gpt-4o-mini") writer = Agent("writer", model="gpt-4o-mini") editor = Agent("editor", model="gpt-4o-mini") pipeline = sequential(researcher, writer, editor) result = pipeline("Write about AI safety") ``` -------------------------------- ### Set API Keys as Environment Variables Source: https://github.com/menonpg/litecrew/blob/main/README.md Configure your API keys by setting them as environment variables. litecrew automatically picks these up for use with libraries like openai and anthropic. ```bash # Set your keys as environment variables (standard practice) export OPENAI_API_KEY="sk-..." export ANTHROPIC_API_KEY="sk-ant-..." ``` -------------------------------- ### Agent with Tools Source: https://github.com/menonpg/litecrew/blob/main/README.md Integrate custom tools into an agent, allowing it to perform specific actions or retrieve information. Tools are defined using a schema. ```python from litecrew import Agent, tool @tool(schema={ "type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"] }) def search(query: str) -> str: return f"Results for: {query}" agent = Agent("assistant", tools=[search]) response = agent("Search for the latest AI news") ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/menonpg/litecrew/blob/main/README.md Run the litecrew test suite with code coverage enabled using pytest. ```bash pytest tests/ --cov=litecrew ``` -------------------------------- ### Configure litecrew for Local Models via OpenAI Compatibility Source: https://github.com/menonpg/litecrew/blob/main/README.md Point litecrew to a local OpenAI-compatible API endpoint, such as Ollama. Ensure the API key is set appropriately for the local provider. ```python import openai from litecrew import Agent # Point to your local Ollama server openai.base_url = "http://localhost:11434/v1" openai.api_key = "ollama" # Ollama doesn't need a real key # Use any local model agent = Agent( name="local", model="llama3.2", # or mistral, qwen2.5, phi3, etc. system="You are a helpful assistant." ) response = agent("Explain quantum computing in simple terms.") print(response) ``` -------------------------------- ### Basic Agent and Crew Definition Source: https://github.com/menonpg/litecrew/blob/main/README.md Define agents and orchestrate them using the @crew decorator for sequential execution. This is the simplest way to pass data between agents. ```python from litecrew import Agent, crew researcher = Agent("researcher", model="gpt-4o-mini") writer = Agent("writer", model="claude-3-5-sonnet-20241022") @crew(researcher, writer) def write_article(topic: str) -> str: research = researcher(f"Research {topic}, return key facts") return writer(f"Write article using: {research}") article = write_article("quantum computing") ``` -------------------------------- ### Agent with Persistent Memory Source: https://github.com/menonpg/litecrew/blob/main/README.md Add persistent memory to an agent using the `with_memory` function. The agent will remember information across different sessions. ```python from litecrew import Agent, with_memory agent = Agent("assistant", model="gpt-4o-mini") agent = with_memory(agent, namespace="my-assistant") # Agent now remembers across sessions agent("My name is Alice and I work at Acme Corp") # ... later, even after restart ... agent("Where do I work?") # "You work at Acme Corp" ``` -------------------------------- ### Parallel Agent Execution Source: https://github.com/menonpg/litecrew/blob/main/README.md Execute multiple agents concurrently on the same input. Each agent processes the input independently. Useful for parallel reviews or analysis. ```python from litecrew import Agent, parallel security = Agent("security", system="Review for security issues.") performance = Agent("performance", system="Review for performance.") style = Agent("style", system="Review for code style.") review_all = parallel(security, performance, style) results = review_all("def get_user(id): return db.query(f'SELECT * FROM users WHERE id={id}')") # Returns: ["SQL injection risk...", "Consider caching...", "Use parameterized queries..."] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.