Skip to content

Commit 5a408c1

Browse files
committed
feat(agent): add FFI patterns and Default impls for config structs
- Add C extension/FFI patterns to agent prompts (Python, Rust, Node.js, OCaml, Haskell) - Add Default impl for RetryConfig (max_attempts=3, delay_ms=1000) - Add Default impl for AgenticConfig with sensible defaults Closes: fluent_cli-s27, fluent_cli-jc2, fluent_cli-g3o
1 parent f2db023 commit 5a408c1

3 files changed

Lines changed: 104 additions & 0 deletions

File tree

crates/fluent-agent/src/prompts.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,84 @@ go install ./cmd/program
631631
- **Wrong compiler version**: Check required GCC/Clang version
632632
- **Path issues**: Set LD_LIBRARY_PATH, PKG_CONFIG_PATH
633633
- **Out of memory**: Reduce parallelism (-j1)
634+
635+
# C EXTENSIONS AND FFI PATTERNS
636+
637+
## Python C Extensions
638+
When building Python packages with C extensions:
639+
```bash
640+
# Install build dependencies
641+
apt-get install python3-dev build-essential
642+
643+
# Common packages needing compilation
644+
pip install numpy pandas scipy # May need: libopenblas-dev, liblapack-dev
645+
pip install pillow # May need: libjpeg-dev, libpng-dev
646+
pip install cryptography # May need: libssl-dev, libffi-dev
647+
648+
# Build from source with verbose output
649+
pip install --no-binary :all: package_name -v
650+
```
651+
652+
## Rust FFI
653+
When working with Rust foreign function interfaces:
654+
```rust
655+
// Calling C from Rust
656+
extern "C" {
657+
fn c_function(arg: i32) -> i32;
658+
}
659+
660+
// Exposing Rust to C
661+
#[no_mangle]
662+
pub extern "C" fn rust_function(arg: i32) -> i32 {
663+
arg * 2
664+
}
665+
```
666+
667+
Build with:
668+
```bash
669+
cargo build --release
670+
# Library in target/release/libname.so (Linux) or .dylib (macOS)
671+
```
672+
673+
## Node.js Native Modules
674+
When building native Node.js modules:
675+
```bash
676+
# Install build tools
677+
npm install -g node-gyp
678+
apt-get install build-essential python3
679+
680+
# Rebuild native modules
681+
npm rebuild
682+
# or for specific package
683+
npm rebuild package-name
684+
```
685+
686+
## Common FFI Issues
687+
1. **Missing compiler**: Install `gcc`, `clang`, or `build-essential`
688+
2. **Missing Python headers**: Install `python3-dev` or `python3-devel`
689+
3. **ABI mismatch**: Rebuild with correct Python/Node version
690+
4. **Architecture mismatch**: Ensure 64-bit libs for 64-bit runtime
691+
5. **Linking errors**: Check `LD_LIBRARY_PATH`, install missing `-dev` packages
692+
693+
## OCaml and Functional Languages
694+
For OCaml projects:
695+
```bash
696+
# Install OCaml toolchain
697+
apt-get install ocaml opam
698+
opam init
699+
opam install dune
700+
701+
# Build project
702+
dune build
703+
```
704+
705+
For Haskell:
706+
```bash
707+
# Install GHC and Cabal
708+
apt-get install ghc cabal-install
709+
cabal update
710+
cabal build
711+
```
634712
"#;
635713

636714
/// Tool descriptions for inclusion in prompts

crates/fluent-cli/src/agentic.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,23 @@ pub struct AgenticConfig {
212212
pub dry_run: bool,
213213
}
214214

215+
impl Default for AgenticConfig {
216+
fn default() -> Self {
217+
Self {
218+
goal_description: String::new(),
219+
agent_config_path: "agent_config.json".to_string(),
220+
max_iterations: 50,
221+
enable_tools: true,
222+
enable_reflection: false,
223+
config_path: "fluent_config.toml".to_string(),
224+
model_override: None,
225+
gen_retries: Some(3),
226+
min_html_size: Some(1000),
227+
dry_run: false,
228+
}
229+
}
230+
}
231+
215232
impl AgenticConfig {
216233
/// Create a new agentic configuration
217234
///

crates/fluent-engines/src/pipeline_executor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ pub struct RetryConfig {
115115
pub delay_ms: u64,
116116
}
117117

118+
impl Default for RetryConfig {
119+
fn default() -> Self {
120+
Self {
121+
max_attempts: 3,
122+
delay_ms: 1000,
123+
}
124+
}
125+
}
126+
118127
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
119128
pub struct PipelineState {
120129
pub current_step: usize,

0 commit comments

Comments
 (0)