fenn.agents¶

- class fenn.agents.LLMClient(provider=None, model=None, api_key=None, api_key_env=None, base_url=None)[source]¶
Bases:
objectUnified LLM client supporting all major providers via an OpenAI-compatible API.
- Parameters:
provider (str, optional) – Provider name (e.g. “openai”, “anthropic”, “openrouter”, “ollama”). Auto-detected from model name or base_url when omitted.
model (str, optional) – Model identifier. Defaults to the provider’s recommended default.
api_key (str, optional) – API key. Takes priority over api_key_env and environment lookup.
api_key_env (str, optional) – Environment variable name to read the API key from. Overrides the provider’s default env var (e.g. OPENROUTER_API_KEY).
base_url (str, optional) – Custom API base URL. Overrides the provider’s default endpoint.
- ask(prompt, schema=None, retries=3)[source]¶
Send a single prompt and return the response.
- Parameters:
prompt (str) – The user message to send.
schema (pydantic.BaseModel, optional) – If provided, validates the response against this schema.
retries (int) – Retry attempts on rate limit errors.
- Return type:
str or pydantic.BaseModel
- chat_complete(messages, schema=None, retries=3)[source]¶
Call the chat completions API with a list of message dicts.
- Parameters:
messages (list of dict) – Messages in OpenAI format: [{“role”: “user”, “content”: “…”}].
schema (pydantic.BaseModel, optional) – If provided, instructs the model to return JSON matching this schema.
retries (int) – Number of retry attempts on rate limit errors.
- Return type:
str or pydantic.BaseModel
- class fenn.agents.RAGNode(sources=None, query_key='query', context_key='rag_context', chunks_key='rag_chunks', top_k=5, next_action='default', faiss=False, embedding_provider='local', embedding_model='all-MiniLM-L6-v2', embedding_api_key=None, chunk_mode='smart', persist_path=None)[source]¶
Bases:
NodeFlow node that retrieves relevant context from indexed sources.
Loads and indexes all sources once at construction time, then per run queries the index using
shared[query_key]and writes the results intoshared[chunks_key]andshared[context_key].- Parameters:
sources (str or list of str, optional) – File paths, folder paths, or URLs to load and index on init. Additional sources can be indexed later with
add_source().query_key (str) – Key in
sharedthat holds the user query. Default:"query".context_key (str) – Key written into
sharedwith the concatenated chunk text. Default:"rag_context".chunks_key (str) – Key written into
sharedwith the raw list of chunks. Default:"rag_chunks".top_k (int) – Maximum number of chunks to retrieve. Default: 5.
next_action (str) – Action string returned by
post(), used byFlow.get_next_node(). Default:"default".faiss (bool) – Use FAISS semantic search instead of BM25. Default: False.
embedding_provider (str) – Embedding provider (only used when faiss=True). Default:
"local".embedding_model (str) – Embedding model (only used when faiss=True). Default:
"all-MiniLM-L6-v2".embedding_api_key (str, optional) – API key for the embedding provider.
chunk_mode (str) – Document chunking strategy. One of
"smart","paragraphs","sentences","fixed". Default:"smart".persist_path (str or Path, optional) – Directory to save/load the FAISS index. Only used when faiss=True.